Bandcamp: parse date

This commit is contained in:
Fynn Godau 2020-06-04 14:09:21 +02:00
parent 6822fe3dc8
commit 1be20ceeec
4 changed files with 24 additions and 6 deletions

View File

@ -77,7 +77,7 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
@Nullable @Nullable
@Override @Override
public String getTextualUploadDate() { public String getTextualUploadDate() {
return showInfo.getString("published_date").replace(" 00:00:00 GMT", ""); return showInfo.getString("published_date");
} }
@Nonnull @Nonnull

View File

@ -20,7 +20,11 @@ import org.schabi.newpipe.extractor.stream.*;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -96,13 +100,21 @@ public class BandcampStreamExtractor extends StreamExtractor {
@Nullable @Nullable
@Override @Override
public String getTextualUploadDate() { public String getTextualUploadDate() {
return current.getString("publish_date").replaceAll(" \\d+:\\d+:\\d+ .+", ""); return current.getString("publish_date");
} }
@Nullable @Nullable
@Override @Override
public DateWrapper getUploadDate() { public DateWrapper getUploadDate() throws ParsingException {
return null; 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) {
e.printStackTrace();
throw new ParsingException("Could not extract date", e);
}
} }
@Nonnull @Nonnull

View File

@ -12,6 +12,7 @@ import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamE
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
import java.io.IOException; import java.io.IOException;
import java.util.Calendar;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp; import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
@ -57,7 +58,11 @@ public class BandcampRadioStreamExtractorTest {
@Test @Test
public void testGetTextualUploadDate() throws ParsingException { public void testGetTextualUploadDate() throws ParsingException {
assertEquals("16 May 2017", e.getTextualUploadDate()); assertEquals("16 May 2017", e.getTextualUploadDate());
}
@Test
public void testUploadDate() throws ParsingException {
assertEquals(136, e.getUploadDate().date().get(Calendar.DAY_OF_YEAR));
} }
@Test @Test

View File

@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamE
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
import java.io.IOException; import java.io.IOException;
import java.util.Calendar;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -61,8 +62,8 @@ public class BandcampStreamExtractorTest {
} }
@Test @Test
public void testUploadDate() { public void testUploadDate() throws ParsingException {
assertEquals("27 Sep 2019", extractor.getTextualUploadDate()); assertEquals(270, extractor.getUploadDate().date().get(Calendar.DAY_OF_YEAR));
} }
@Test @Test