mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-14 22:30:33 +05:30
Bandcamp: Move code from SearchExtractor to InfoItemExtractors
This commit is contained in:
parent
00c0333059
commit
82099592c7
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
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.channel.ChannelInfoItemExtractor;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
|
||||||
@ -9,11 +10,21 @@ public class BandcampChannelInfoItemExtractor implements ChannelInfoItemExtracto
|
|||||||
|
|
||||||
private String name, url, image, location;
|
private String name, url, image, location;
|
||||||
|
|
||||||
public BandcampChannelInfoItemExtractor(String name, String url, String image, String location) {
|
public BandcampChannelInfoItemExtractor(Element searchResult) {
|
||||||
this.name = name;
|
|
||||||
this.url = url;
|
Element resultInfo = searchResult.getElementsByClass("result-info").first();
|
||||||
this.image = image;
|
|
||||||
this.location = location;
|
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
|
@Override
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
||||||
|
|
||||||
|
import com.grack.nanojson.JsonObject;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl;
|
||||||
|
|
||||||
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
public class BandcampPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
||||||
|
@ -43,49 +43,26 @@ public class BandcampSearchExtractor extends SearchExtractor {
|
|||||||
for (Element searchResult :
|
for (Element searchResult :
|
||||||
searchResultsElements) {
|
searchResultsElements) {
|
||||||
|
|
||||||
Element resultInfo = searchResult.getElementsByClass("result-info").first();
|
String type = searchResult.getElementsByClass("result-info").first()
|
||||||
|
|
||||||
String type = resultInfo
|
|
||||||
.getElementsByClass("itemtype").first().text();
|
.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) {
|
switch (type) {
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
case "FAN":
|
case "FAN":
|
||||||
//collector.commit Channel (?) with heading, url, image
|
// don't display fan results
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ARTIST":
|
case "ARTIST":
|
||||||
collector.commit(new BandcampChannelInfoItemExtractor(heading, url, image, subhead));
|
collector.commit(new BandcampChannelInfoItemExtractor(searchResult));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ALBUM":
|
case "ALBUM":
|
||||||
String artist = subhead.split(" by")[0];
|
collector.commit(new BandcampPlaylistInfoItemExtractor(searchResult));
|
||||||
String length = resultInfo.getElementsByClass("length").text();
|
|
||||||
int tracks = Integer.parseInt(length.split(" track")[0]);
|
|
||||||
collector.commit(new BandcampPlaylistInfoItemExtractor(heading, artist, url, image, tracks));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "TRACK":
|
case "TRACK":
|
||||||
String[] splitBy = subhead.split(" by");
|
collector.commit(new BandcampStreamInfoItemExtractor(searchResult));
|
||||||
String artist1 = null;
|
|
||||||
if (splitBy.length > 1) {
|
|
||||||
artist1 = subhead.split(" by")[1];
|
|
||||||
}
|
|
||||||
collector.commit(new BandcampStreamInfoItemExtractor(heading, url, image, artist1));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
||||||
|
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
@ -31,6 +32,25 @@ public class BandcampStreamInfoItemExtractor implements StreamInfoItemExtractor
|
|||||||
this(title, url, cover, artist, -1);
|
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) {
|
public BandcampStreamInfoItemExtractor(String title, String url, String cover, String artist, long duration) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
Loading…
Reference in New Issue
Block a user