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.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||
import org.schabi.newpipe.extractor.utils.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class BandcampExtractorHelper {
|
||||
|
||||
|
@ -142,4 +144,15 @@ public class BandcampExtractorHelper {
|
|||
public static String getImageUrl(long id, boolean album) {
|
||||
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
|
||||
@Override
|
||||
public String getTextualUploadDate() {
|
||||
return show.getString("date").replace(" 00:00:00 GMT", "");
|
||||
return show.getString("date");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DateWrapper getUploadDate() {
|
||||
return null;
|
||||
public DateWrapper getUploadDate() throws ParsingException {
|
||||
return BandcampExtractorHelper.parseDate(getTextualUploadDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -106,14 +106,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||
@Nullable
|
||||
@Override
|
||||
public DateWrapper getUploadDate() throws ParsingException {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
return BandcampExtractorHelper.parseDate(getTextualUploadDate());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
Loading…
Reference in New Issue