From 00c03330596b00b2c6246cc29b5dccd84df1d7d5 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Mon, 20 Apr 2020 22:06:48 +0200 Subject: [PATCH] Bandcamp: Fetch channelInfo in onFetchPage --- .../extractors/BandcampChannelExtractor.java | 5 +-- .../extractors/BandcampFeaturedExtractor.java | 8 +--- .../BandcampPlaylistInfoItemExtractor.java | 40 ++++++++++++++----- .../BandcampChannelExtractorTest.java | 10 ++++- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelExtractor.java index fd068e60e..66d972ce0 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelExtractor.java @@ -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 diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampFeaturedExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampFeaturedExtractor.java index 37bfd1aea..986bdc3b2 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampFeaturedExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampFeaturedExtractor.java @@ -72,13 +72,7 @@ public class BandcampFeaturedExtractor extends KioskExtractor { 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(c, null); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java index 61551bac5..e146766c3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistInfoItemExtractor.java @@ -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 diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelExtractorTest.java index 6aea55939..0d861eab3 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelExtractorTest.java @@ -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()); } }