diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelInfoItemExtractor.java index 33d999117..2ff853407 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelInfoItemExtractor.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors; +import org.jsoup.nodes.Element; import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -9,11 +10,21 @@ public class BandcampChannelInfoItemExtractor implements ChannelInfoItemExtracto private String name, url, image, location; - public BandcampChannelInfoItemExtractor(String name, String url, String image, String location) { - this.name = name; - this.url = url; - this.image = image; - this.location = location; + public BandcampChannelInfoItemExtractor(Element searchResult) { + + Element resultInfo = searchResult.getElementsByClass("result-info").first(); + + Element img = searchResult.getElementsByClass("art").first() + .getElementsByTag("img").first(); + if (img != null) { + image = img.attr("src"); + } + + name = resultInfo.getElementsByClass("heading").text(); + + location = resultInfo.getElementsByClass("subhead").text(); + + url = resultInfo.getElementsByClass("itemurl").text(); } @Override 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 e146766c3..75d841723 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,10 +1,9 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors; +import com.grack.nanojson.JsonObject; 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 { 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 cd27a01d9..3f6a35b1a 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 @@ -43,49 +43,26 @@ public class BandcampSearchExtractor extends SearchExtractor { for (Element searchResult : searchResultsElements) { - Element resultInfo = searchResult.getElementsByClass("result-info").first(); - - String type = resultInfo + String type = searchResult.getElementsByClass("result-info").first() .getElementsByClass("itemtype").first().text(); - String image = null; - Element img = searchResult.getElementsByClass("art").first() - .getElementsByTag("img").first(); - if (img != null) { - image = img.attr("src"); - } - - String heading = resultInfo.getElementsByClass("heading").text(); - - String subhead = resultInfo.getElementsByClass("subhead").text(); - - String url = resultInfo.getElementsByClass("itemurl").text(); - switch (type) { default: continue; case "FAN": - //collector.commit Channel (?) with heading, url, image + // don't display fan results break; case "ARTIST": - collector.commit(new BandcampChannelInfoItemExtractor(heading, url, image, subhead)); + collector.commit(new BandcampChannelInfoItemExtractor(searchResult)); break; case "ALBUM": - String artist = subhead.split(" by")[0]; - String length = resultInfo.getElementsByClass("length").text(); - int tracks = Integer.parseInt(length.split(" track")[0]); - collector.commit(new BandcampPlaylistInfoItemExtractor(heading, artist, url, image, tracks)); + collector.commit(new BandcampPlaylistInfoItemExtractor(searchResult)); break; case "TRACK": - String[] splitBy = subhead.split(" by"); - String artist1 = null; - if (splitBy.length > 1) { - artist1 = subhead.split(" by")[1]; - } - collector.commit(new BandcampStreamInfoItemExtractor(heading, url, image, artist1)); + collector.commit(new BandcampStreamInfoItemExtractor(searchResult)); break; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamInfoItemExtractor.java index dd51f7692..e29ac241b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamInfoItemExtractor.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.services.bandcamp.extractors; +import org.jsoup.nodes.Element; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; @@ -31,6 +32,25 @@ public class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor this(title, url, cover, artist, -1); } + public BandcampStreamInfoItemExtractor(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(); + + String subhead = resultInfo.getElementsByClass("subhead").text(); + String[] splitBy = subhead.split(" by"); + if (splitBy.length > 1) { + artist = subhead.split(" by")[1]; + } + } + public BandcampStreamInfoItemExtractor(String title, String url, String cover, String artist, long duration) { this.title = title; this.url = url;