[Bandcamp] Show additional info in radio kiosk

A newer version of the radio list API delivers additional fields. Thanks
@crisp5.
This commit is contained in:
Fynn Godau 2024-07-21 23:59:10 +02:00
parent 4aaab63c12
commit 227c6894a7
4 changed files with 17 additions and 11 deletions

View File

@ -24,7 +24,7 @@ import static org.schabi.newpipe.extractor.services.bandcamp.extractors.Bandcamp
public class BandcampRadioExtractor extends KioskExtractor<StreamInfoItem> { public class BandcampRadioExtractor extends KioskExtractor<StreamInfoItem> {
public static final String KIOSK_RADIO = "Radio"; public static final String KIOSK_RADIO = "Radio";
public static final String RADIO_API_URL = BASE_API_URL + "/bcweekly/1/list"; public static final String RADIO_API_URL = BASE_API_URL + "/bcweekly/3/list";
private JsonObject json = null; private JsonObject json = null;

View File

@ -35,6 +35,12 @@ public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
return 0; return 0;
} }
@Nullable
@Override
public String getShortDescription() {
return show.getString("desc");
}
@Nullable @Nullable
@Override @Override
public String getTextualUploadDate() { public String getTextualUploadDate() {
@ -75,8 +81,8 @@ public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
@Override @Override
public String getUploaderName() { public String getUploaderName() {
// JSON does not contain uploader name // The "title" field contains the title of the series, e.g. "Bandcamp Weekly".
return ""; return show.getString("title");
} }
@Override @Override

View File

@ -28,7 +28,7 @@ public class BandcampFeaturedLinkHandlerFactoryTest {
assertTrue(linkHandler.acceptUrl("https://bandcamp.com/?show=1")); assertTrue(linkHandler.acceptUrl("https://bandcamp.com/?show=1"));
assertTrue(linkHandler.acceptUrl("http://bandcamp.com/?show=2")); assertTrue(linkHandler.acceptUrl("http://bandcamp.com/?show=2"));
assertTrue(linkHandler.acceptUrl("https://bandcamp.com/api/mobile/24/bootstrap_data")); assertTrue(linkHandler.acceptUrl("https://bandcamp.com/api/mobile/24/bootstrap_data"));
assertTrue(linkHandler.acceptUrl("https://bandcamp.com/api/bcweekly/1/list")); assertTrue(linkHandler.acceptUrl("https://bandcamp.com/api/bcweekly/3/list"));
assertFalse(linkHandler.acceptUrl("https://bandcamp.com/?show=")); assertFalse(linkHandler.acceptUrl("https://bandcamp.com/?show="));
assertFalse(linkHandler.acceptUrl("https://bandcamp.com/?show=a")); assertFalse(linkHandler.acceptUrl("https://bandcamp.com/?show=a"));
@ -38,7 +38,7 @@ public class BandcampFeaturedLinkHandlerFactoryTest {
@Test @Test
public void testGetUrl() throws ParsingException { public void testGetUrl() throws ParsingException {
assertEquals("https://bandcamp.com/api/mobile/24/bootstrap_data", linkHandler.getUrl("Featured")); assertEquals("https://bandcamp.com/api/mobile/24/bootstrap_data", linkHandler.getUrl("Featured"));
assertEquals("https://bandcamp.com/api/bcweekly/1/list", linkHandler.getUrl("Radio")); assertEquals("https://bandcamp.com/api/bcweekly/3/list", linkHandler.getUrl("Radio"));
} }
@Test @Test
@ -46,7 +46,7 @@ public class BandcampFeaturedLinkHandlerFactoryTest {
assertEquals("Featured", linkHandler.getId("http://bandcamp.com/api/mobile/24/bootstrap_data")); assertEquals("Featured", linkHandler.getId("http://bandcamp.com/api/mobile/24/bootstrap_data"));
assertEquals("Featured", linkHandler.getId("https://bandcamp.com/api/mobile/24/bootstrap_data")); assertEquals("Featured", linkHandler.getId("https://bandcamp.com/api/mobile/24/bootstrap_data"));
assertEquals("Radio", linkHandler.getId("http://bandcamp.com/?show=1")); assertEquals("Radio", linkHandler.getId("http://bandcamp.com/?show=1"));
assertEquals("Radio", linkHandler.getId("https://bandcamp.com/api/bcweekly/1/list")); assertEquals("Radio", linkHandler.getId("https://bandcamp.com/api/bcweekly/3/list"));
} }
} }

View File

@ -8,6 +8,7 @@ import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest; import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.DefaultTests;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioExtractor; import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
@ -35,15 +36,14 @@ public class BandcampRadioExtractorTest implements BaseListExtractorTest {
} }
@Test @Test
public void testRadioCount() throws ExtractionException, IOException { public void testRadioCount() {
final List<StreamInfoItem> list = extractor.getInitialPage().getItems(); final List<StreamInfoItem> list = extractor.getInitialPage().getItems();
assertTrue(list.size() > 300); assertTrue(list.size() > 300);
} }
@Test @Test
public void testRelatedItems() throws Exception { public void testRelatedItems() throws Exception {
// DefaultTests.defaultTestRelatedItems(extractor); DefaultTests.defaultTestRelatedItems(extractor);
// Would fail because BandcampRadioInfoItemExtractor.getUploaderName() returns an empty String
} }
@Test @Test
@ -68,11 +68,11 @@ public class BandcampRadioExtractorTest implements BaseListExtractorTest {
@Test @Test
public void testUrl() throws Exception { public void testUrl() throws Exception {
assertEquals("https://bandcamp.com/api/bcweekly/1/list", extractor.getUrl()); assertEquals("https://bandcamp.com/api/bcweekly/3/list", extractor.getUrl());
} }
@Test @Test
public void testOriginalUrl() throws Exception { public void testOriginalUrl() throws Exception {
assertEquals("https://bandcamp.com/api/bcweekly/1/list", extractor.getOriginalUrl()); assertEquals("https://bandcamp.com/api/bcweekly/3/list", extractor.getOriginalUrl());
} }
} }