Bandcamp: Move code from SearchExtractor to InfoItemExtractors

This commit is contained in:
Fynn Godau 2020-04-20 22:30:00 +02:00
parent 00c0333059
commit 82099592c7
4 changed files with 42 additions and 35 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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;
}

View File

@ -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;