Merge pull request #610 from TeamNewPipe/bandcamp_related_items
Extract related bandcamp items
This commit is contained in:
commit
c14f6db14a
|
@ -14,6 +14,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
||||||
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector;
|
||||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||||
import org.schabi.newpipe.extractor.stream.Description;
|
import org.schabi.newpipe.extractor.stream.Description;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamSegment;
|
import org.schabi.newpipe.extractor.stream.StreamSegment;
|
||||||
|
@ -165,4 +166,10 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor {
|
||||||
public Privacy getPrivacy() {
|
public Privacy getPrivacy() {
|
||||||
return Privacy.PUBLIC;
|
return Privacy.PUBLIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlaylistInfoItemsCollector getRelatedItems() {
|
||||||
|
// Contrary to other Bandcamp streams, radio streams don't have related items
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Created by Fynn Godau 2021, licensed GNU GPL version 3 or later
|
||||||
|
|
||||||
|
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
||||||
|
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts recommended albums from tracks' website
|
||||||
|
*/
|
||||||
|
public class BandcampRelatedPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
||||||
|
private final Element relatedAlbum;
|
||||||
|
|
||||||
|
public BandcampRelatedPlaylistInfoItemExtractor(@Nonnull Element relatedAlbum) {
|
||||||
|
this.relatedAlbum = relatedAlbum;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() throws ParsingException {
|
||||||
|
return relatedAlbum.getElementsByClass("release-title").text();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUrl() throws ParsingException {
|
||||||
|
return relatedAlbum.getElementsByClass("title-and-artist").attr("abs:href");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getThumbnailUrl() throws ParsingException {
|
||||||
|
return relatedAlbum.getElementsByClass("album-art").attr("src");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUploaderName() throws ParsingException {
|
||||||
|
return relatedAlbum.getElementsByClass("by-artist").text().replace("by ", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getStreamCount() throws ParsingException {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
||||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||||
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector;
|
||||||
import org.schabi.newpipe.extractor.stream.*;
|
import org.schabi.newpipe.extractor.stream.*;
|
||||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
@ -245,8 +246,17 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamInfoItemsCollector getRelatedItems() {
|
public PlaylistInfoItemsCollector getRelatedItems() {
|
||||||
return null;
|
|
||||||
|
PlaylistInfoItemsCollector collector = new PlaylistInfoItemsCollector(getServiceId());
|
||||||
|
|
||||||
|
Elements recommendedAlbums = document.getElementsByClass("recommended-album");
|
||||||
|
|
||||||
|
for (Element album : recommendedAlbums) {
|
||||||
|
collector.commit(new BandcampRelatedPlaylistInfoItemExtractor(album));
|
||||||
|
}
|
||||||
|
|
||||||
|
return collector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class BandcampStreamExtractorTest extends DefaultStreamExtractorTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean expectedHasRelatedItems() {
|
public boolean expectedHasRelatedItems() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue