Bandcamp: Fetch channelInfo in onFetchPage

This commit is contained in:
Fynn Godau 2020-04-20 22:06:48 +02:00
parent 433d72c26a
commit 00c0333059
4 changed files with 41 additions and 22 deletions

View File

@ -22,10 +22,8 @@ public class BandcampChannelExtractor extends ChannelExtractor {
private JsonObject channelInfo;
public BandcampChannelExtractor(StreamingService service, ListLinkHandler linkHandler) throws ParsingException {
public BandcampChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
super(service, linkHandler);
channelInfo = getArtistDetails(getId());
}
/**
@ -156,6 +154,7 @@ public class BandcampChannelExtractor extends ChannelExtractor {
@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
channelInfo = getArtistDetails(getId());
}
@Nonnull

View File

@ -72,13 +72,7 @@ public class BandcampFeaturedExtractor extends KioskExtractor<InfoItem> {
continue;
}
c.commit(new BandcampPlaylistInfoItemExtractor(
featuredStory.getString("album_title"),
featuredStory.getString("band_name"),
featuredStory.getString("item_url"),
featuredStory.has("art_id") ? getImageUrl(featuredStory.getLong("art_id"), true) : "",
featuredStory.getInt("num_streamable_tracks")
));
c.commit(new BandcampPlaylistInfoItemExtractor(featuredStory));
}
return new InfoItemsPage<InfoItem>(c, null);

View File

@ -1,24 +1,44 @@
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.jsoup.nodes.Element;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
import java.io.IOException;
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl;
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
private String title, artist, url, cover;
private int trackCount;
public BandcampPlaylistInfoItemExtractor(String title, String artist, String url, String cover, int trackCount) {
this.title = title;
this.artist = artist;
this.url = url;
this.cover = cover;
this.trackCount = trackCount;
public BandcampPlaylistInfoItemExtractor(Element searchResult) {
Element resultInfo = searchResult.getElementsByClass("result-info").first();
Element img = searchResult.getElementsByClass("art").first()
.getElementsByTag("img").first();
if (img != null) {
cover = img.attr("src");
}
title = resultInfo.getElementsByClass("heading").text();
url = resultInfo.getElementsByClass("itemurl").text();
artist = resultInfo.getElementsByClass("subhead").text()
.split(" by")[0];
String length = resultInfo.getElementsByClass("length").text();
trackCount = Integer.parseInt(length.split(" track")[0]);
}
public BandcampPlaylistInfoItemExtractor(JsonObject featuredStory) {
title = featuredStory.getString("album_title");
artist = featuredStory.getString("band_name");
url = featuredStory.getString("item_url");
cover = featuredStory.has("art_id") ? getImageUrl(featuredStory.getLong("art_id"), true) : "";
trackCount = featuredStory.getInt("num_streamable_tracks");
}
@Override

View File

@ -6,6 +6,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor;
@ -18,12 +19,17 @@ import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
public class BandcampChannelExtractorTest {
private static BandcampChannelExtractor extractor;
private static ChannelExtractor noAvatarExtractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (BandcampChannelExtractor) Bandcamp
.getChannelExtractor("https://zachbenson.bandcamp.com/");
extractor.fetchPage();
noAvatarExtractor = Bandcamp.getChannelExtractor("https://powertothequeerkids.bandcamp.com/");
noAvatarExtractor.fetchPage();
}
@Test
@ -51,11 +57,11 @@ public class BandcampChannelExtractorTest {
@Test
public void testGetNoAvatar() throws ExtractionException {
assertEquals("", Bandcamp.getChannelExtractor("https://powertothequeerkids.bandcamp.com/").getAvatarUrl());
assertEquals("", noAvatarExtractor.getAvatarUrl());
}
@Test
public void testGetNoBanner() throws ExtractionException {
assertEquals("", Bandcamp.getChannelExtractor("https://powertothequeerkids.bandcamp.com/").getBannerUrl());
assertEquals("", noAvatarExtractor.getBannerUrl());
}
}