From 13e4908b832e042141c3d8577b3cec4e69ee27d0 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Sun, 22 Dec 2019 14:07:56 +0100 Subject: [PATCH] Bandcamp search extractor: read track count from result page --- .../BandcampPlaylistInfoItemExtractor.java | 16 +++++----------- .../extractors/BandcampSearchExtractor.java | 4 +++- .../bandcamp/BandcampSearchExtractorTest.java | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) 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 5257691e..61551bac 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 @@ -11,14 +11,14 @@ import java.io.IOException; public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor { private String title, artist, url, cover; - private StreamingService service; + private int trackCount; - public BandcampPlaylistInfoItemExtractor(String title, String artist, String url, String cover, StreamingService service) { + 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.service = service; + this.trackCount = trackCount; } @Override @@ -27,14 +27,8 @@ public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtrac } @Override - public long getStreamCount() throws ParsingException { - try { - PlaylistExtractor extractor = service.getPlaylistExtractor(url); - extractor.fetchPage(); - return extractor.getStreamCount(); - } catch (ExtractionException | IOException e) { - throw new ParsingException("Could not find out how many tracks there are", e); - } + public long getStreamCount() { + return trackCount; } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSearchExtractor.java index 31b1b4b8..6831cdf6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSearchExtractor.java @@ -74,7 +74,9 @@ public class BandcampSearchExtractor extends SearchExtractor { case "ALBUM": String artist = subhead.split(" by")[0]; - collector.commit(new BandcampPlaylistInfoItemExtractor(heading, artist, url, image, getService())); + String length = resultInfo.getElementsByClass("length").text(); + int tracks = Integer.parseInt(length.split(" track")[0]); + collector.commit(new BandcampPlaylistInfoItemExtractor(heading, artist, url, image, tracks)); break; case "TRACK": diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampSearchExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampSearchExtractorTest.java index 8cffcf73..1e6f9b57 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampSearchExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampSearchExtractorTest.java @@ -85,7 +85,7 @@ public class BandcampSearchExtractorTest { assertTrue(minecraft.getThumbnailUrl().contains("f4.bcbits.com/img/")); assertEquals("https://c418.bandcamp.com/album/minecraft-volume-alpha", minecraft.getUrl()); - // Verify that playlists get counted correctly + // Verify that playlist tracks counts get extracted correctly assertEquals(24, ((PlaylistInfoItem) minecraft).getStreamCount()); }