From 90b5c005997b0ff30caf9e7414fe96df586e25b0 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Tue, 13 Apr 2021 17:55:19 +0200 Subject: [PATCH 1/2] Extract related items #593 --- ...dcampRelatedPlaylistInfoItemExtractor.java | 45 +++++++++++++++++++ .../extractors/BandcampStreamExtractor.java | 14 +++++- .../bandcamp/BandcampStreamExtractorTest.java | 2 +- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRelatedPlaylistInfoItemExtractor.java diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRelatedPlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRelatedPlaylistInfoItemExtractor.java new file mode 100644 index 00000000..7d639131 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRelatedPlaylistInfoItemExtractor.java @@ -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; + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java index f83e351a..e14a8e91 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java @@ -16,6 +16,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.linkhandler.LinkHandler; 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.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.Utils; @@ -245,8 +246,17 @@ public class BandcampStreamExtractor extends StreamExtractor { } @Override - public StreamInfoItemsCollector getRelatedItems() { - return null; + public PlaylistInfoItemsCollector getRelatedItems() { + + PlaylistInfoItemsCollector collector = new PlaylistInfoItemsCollector(getServiceId()); + + Elements recommendedAlbums = document.getElementsByClass("recommended-album"); + + for (Element album : recommendedAlbums) { + collector.commit(new BandcampRelatedPlaylistInfoItemExtractor(album)); + } + + return collector; } @Override diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java index 34d3459f..3cbb3004 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java @@ -126,7 +126,7 @@ public class BandcampStreamExtractorTest extends DefaultStreamExtractorTest { @Override public boolean expectedHasRelatedItems() { - return false; + return true; } @Override From 36718767215d5a12becbf3176d5e010a461a338b Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Tue, 13 Apr 2021 19:30:11 +0200 Subject: [PATCH 2/2] Fix bandcamp radio stream extractor --- .../bandcamp/extractors/BandcampRadioStreamExtractor.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java index 92e37b71..000f884b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java @@ -14,6 +14,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; 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.Description; import org.schabi.newpipe.extractor.stream.StreamSegment; @@ -165,4 +166,10 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor { public Privacy getPrivacy() { return Privacy.PUBLIC; } + + @Override + public PlaylistInfoItemsCollector getRelatedItems() { + // Contrary to other Bandcamp streams, radio streams don't have related items + return null; + } }