mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-28 16:00:33 +05:30
Use propper structure in KioskExtractors
Made BandCampRadioExtractor a Kiosk which holds StreamInfoItems and not InfoItems.
This commit is contained in:
parent
54b8e54f80
commit
54aa5b3042
@ -24,6 +24,8 @@ public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem>
|
|||||||
public static final String KIOSK_FEATURED = "Featured";
|
public static final String KIOSK_FEATURED = "Featured";
|
||||||
public static final String FEATURED_API_URL = "https://bandcamp.com/api/mobile/24/bootstrap_data";
|
public static final String FEATURED_API_URL = "https://bandcamp.com/api/mobile/24/bootstrap_data";
|
||||||
|
|
||||||
|
private JsonObject json;
|
||||||
|
|
||||||
public BandcampFeaturedExtractor(final StreamingService streamingService, final ListLinkHandler listLinkHandler,
|
public BandcampFeaturedExtractor(final StreamingService streamingService, final ListLinkHandler listLinkHandler,
|
||||||
final String kioskId) {
|
final String kioskId) {
|
||||||
super(streamingService, listLinkHandler, kioskId);
|
super(streamingService, listLinkHandler, kioskId);
|
||||||
@ -31,7 +33,15 @@ public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||||
|
try {
|
||||||
|
json = JsonParser.object().from(
|
||||||
|
getDownloader().post(
|
||||||
|
FEATURED_API_URL, null, "{\"platform\":\"\",\"version\":0}".getBytes()
|
||||||
|
).responseBody()
|
||||||
|
);
|
||||||
|
} catch (final JsonParserException e) {
|
||||||
|
throw new ParsingException("Could not parse Bandcamp featured API response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -46,35 +56,23 @@ public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem>
|
|||||||
|
|
||||||
final PlaylistInfoItemsCollector c = new PlaylistInfoItemsCollector(getServiceId());
|
final PlaylistInfoItemsCollector c = new PlaylistInfoItemsCollector(getServiceId());
|
||||||
|
|
||||||
try {
|
final JsonArray featuredStories = json.getObject("feed_content")
|
||||||
|
.getObject("stories")
|
||||||
|
.getArray("featured");
|
||||||
|
|
||||||
|
for (int i = 0; i < featuredStories.size(); i++) {
|
||||||
|
final JsonObject featuredStory = featuredStories.getObject(i);
|
||||||
|
|
||||||
final JsonObject json = JsonParser.object().from(
|
if (featuredStory.isNull("album_title")) {
|
||||||
getDownloader().post(
|
// Is not an album, ignore
|
||||||
FEATURED_API_URL, null, "{\"platform\":\"\",\"version\":0}".getBytes()
|
continue;
|
||||||
).responseBody()
|
|
||||||
);
|
|
||||||
|
|
||||||
final JsonArray featuredStories = json.getObject("feed_content")
|
|
||||||
.getObject("stories")
|
|
||||||
.getArray("featured");
|
|
||||||
|
|
||||||
for (int i = 0; i < featuredStories.size(); i++) {
|
|
||||||
final JsonObject featuredStory = featuredStories.getObject(i);
|
|
||||||
|
|
||||||
if (featuredStory.isNull("album_title")) {
|
|
||||||
// Is not an album, ignore
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
c.commit(new BandcampPlaylistInfoItemFeaturedExtractor(featuredStory));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new InfoItemsPage<>(c, null);
|
c.commit(new BandcampPlaylistInfoItemFeaturedExtractor(featuredStory));
|
||||||
} catch (final JsonParserException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new ParsingException("JSON error", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new InfoItemsPage<>(c, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,8 +6,6 @@ import com.grack.nanojson.JsonArray;
|
|||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
|
||||||
import org.schabi.newpipe.extractor.InfoItemsCollector;
|
|
||||||
import org.schabi.newpipe.extractor.Page;
|
import org.schabi.newpipe.extractor.Page;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
@ -15,16 +13,19 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class BandcampRadioExtractor extends KioskExtractor<InfoItem> {
|
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 = "https://bandcamp.com/api/bcweekly/1/list";
|
public static final String RADIO_API_URL = "https://bandcamp.com/api/bcweekly/1/list";
|
||||||
|
|
||||||
|
private JsonObject json = null;
|
||||||
|
|
||||||
public BandcampRadioExtractor(final StreamingService streamingService, final ListLinkHandler linkHandler,
|
public BandcampRadioExtractor(final StreamingService streamingService, final ListLinkHandler linkHandler,
|
||||||
final String kioskId) {
|
final String kioskId) {
|
||||||
super(streamingService, linkHandler, kioskId);
|
super(streamingService, linkHandler, kioskId);
|
||||||
@ -32,7 +33,12 @@ public class BandcampRadioExtractor extends KioskExtractor<InfoItem> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
||||||
|
try {
|
||||||
|
json = JsonParser.object().from(
|
||||||
|
getDownloader().get(RADIO_API_URL).responseBody());
|
||||||
|
} catch (final JsonParserException e) {
|
||||||
|
throw new ExtractionException("Could not parse Bandcamp Radio API response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -43,36 +49,21 @@ public class BandcampRadioExtractor extends KioskExtractor<InfoItem> {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionException {
|
public InfoItemsPage<StreamInfoItem> getInitialPage() {
|
||||||
final InfoItemsCollector c = new StreamInfoItemsCollector(getServiceId());
|
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||||
|
|
||||||
try {
|
final JsonArray radioShows = json.getArray("results");
|
||||||
|
|
||||||
final JsonObject json = JsonParser.object().from(
|
for (int i = 0; i < radioShows.size(); i++) {
|
||||||
getDownloader().get(
|
final JsonObject radioShow = radioShows.getObject(i);
|
||||||
RADIO_API_URL
|
collector.commit(new BandcampRadioInfoItemExtractor(radioShow));
|
||||||
).responseBody()
|
|
||||||
);
|
|
||||||
|
|
||||||
final JsonArray radioShows = json.getArray("results");
|
|
||||||
|
|
||||||
for (int i = 0; i < radioShows.size(); i++) {
|
|
||||||
final JsonObject radioShow = radioShows.getObject(i);
|
|
||||||
|
|
||||||
c.commit(
|
|
||||||
new BandcampRadioInfoItemExtractor(radioShow)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (final JsonParserException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new InfoItemsPage<InfoItem>(c, null);
|
return new InfoItemsPage<>(collector, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InfoItemsPage<InfoItem> getPage(final Page page) {
|
public InfoItemsPage<StreamInfoItem> getPage(final Page page) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ public class BandcampFeaturedExtractorTest implements BaseListExtractorTest {
|
|||||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||||
extractor = (BandcampFeaturedExtractor) Bandcamp
|
extractor = (BandcampFeaturedExtractor) Bandcamp
|
||||||
.getKioskList().getDefaultKioskExtractor();
|
.getKioskList().getDefaultKioskExtractor();
|
||||||
|
extractor.fetchPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -5,11 +5,11 @@ package org.schabi.newpipe.extractor.services.bandcamp;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
|
||||||
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.bandcamp.extractors.BandcampRadioExtractor;
|
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioExtractor;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -31,11 +31,12 @@ public class BandcampRadioExtractorTest implements BaseListExtractorTest {
|
|||||||
extractor = (BandcampRadioExtractor) Bandcamp
|
extractor = (BandcampRadioExtractor) Bandcamp
|
||||||
.getKioskList()
|
.getKioskList()
|
||||||
.getExtractorById("Radio", null);
|
.getExtractorById("Radio", null);
|
||||||
|
extractor.fetchPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRadioCount() throws ExtractionException, IOException {
|
public void testRadioCount() throws ExtractionException, IOException {
|
||||||
final List<InfoItem> list = Bandcamp.getKioskList().getExtractorById("Radio", null).getInitialPage().getItems();
|
final List<StreamInfoItem> list = extractor.getInitialPage().getItems();
|
||||||
assertTrue(list.size() > 300);
|
assertTrue(list.size() > 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user