Bandcamp: parse date from radio info item
This commit is contained in:
parent
39b55b5b42
commit
96de834b67
|
@ -9,11 +9,13 @@ import com.grack.nanojson.JsonWriter;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.text.ParseException;
|
||||||
import java.util.Arrays;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class BandcampExtractorHelper {
|
public class BandcampExtractorHelper {
|
||||||
|
|
||||||
|
@ -142,4 +144,15 @@ public class BandcampExtractorHelper {
|
||||||
public static String getImageUrl(long id, boolean album) {
|
public static String getImageUrl(long id, boolean album) {
|
||||||
return "https://f4.bcbits.com/img/" + (album ? 'a' : "") + id + "_10.jpg";
|
return "https://f4.bcbits.com/img/" + (album ? 'a' : "") + id + "_10.jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static DateWrapper parseDate(String textDate) throws ParsingException {
|
||||||
|
try {
|
||||||
|
Date date = new SimpleDateFormat("dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH).parse(textDate);
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(date);
|
||||||
|
return new DateWrapper(calendar, false);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new ParsingException("Could not extract date", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,13 +33,13 @@ public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getTextualUploadDate() {
|
public String getTextualUploadDate() {
|
||||||
return show.getString("date").replace(" 00:00:00 GMT", "");
|
return show.getString("date");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public DateWrapper getUploadDate() {
|
public DateWrapper getUploadDate() throws ParsingException {
|
||||||
return null;
|
return BandcampExtractorHelper.parseDate(getTextualUploadDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -106,14 +106,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public DateWrapper getUploadDate() throws ParsingException {
|
public DateWrapper getUploadDate() throws ParsingException {
|
||||||
try {
|
return BandcampExtractorHelper.parseDate(getTextualUploadDate());
|
||||||
Date date = new SimpleDateFormat("dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH).parse(getTextualUploadDate());
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
return new DateWrapper(calendar, false);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
throw new ParsingException("Could not extract date", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
Loading…
Reference in New Issue