From 9dc1832733733c6c8ffb7ff675010ba481c94337 Mon Sep 17 00:00:00 2001 From: petlyh <88139840+petlyh@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:51:30 +0100 Subject: [PATCH 1/2] [Bandcamp] Handle paywalled tracks --- .../extractors/BandcampStreamExtractor.java | 5 ++++ .../BandcampPaidStreamExtractorTest.java | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampPaidStreamExtractorTest.java 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 e4120bed8..b4e6098ae 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 @@ -15,6 +15,7 @@ import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.downloader.Downloader; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.PaidContentException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.linkhandler.LinkHandler; import org.schabi.newpipe.extractor.localization.DateWrapper; @@ -57,6 +58,10 @@ public class BandcampStreamExtractor extends StreamExtractor { // In this case, we are actually viewing an album page! throw new ExtractionException("Page is actually an album, not a track"); } + + if (albumJson.getArray("trackinfo").getObject(0).isNull("file")) { + throw new PaidContentException("This track is not available without being purchased"); + } } /** diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampPaidStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampPaidStreamExtractorTest.java new file mode 100644 index 000000000..88eca9fdd --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampPaidStreamExtractorTest.java @@ -0,0 +1,25 @@ +package org.schabi.newpipe.extractor.services.bandcamp; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.schabi.newpipe.extractor.ServiceList.Bandcamp; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.schabi.newpipe.downloader.DownloaderTestImpl; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.PaidContentException; + +public class BandcampPaidStreamExtractorTest { + + @BeforeAll + public static void setUp() { + NewPipe.init(DownloaderTestImpl.getInstance()); + } + + @Test + public void testPaidTrack() throws ExtractionException { + final var extractor = Bandcamp.getStreamExtractor("https://radicaldreamland.bandcamp.com/track/hackmud-continuous-mix"); + assertThrows(PaidContentException.class, extractor::fetchPage); + } +} From e6aad117e70a157b3a7b497756951df9d9465305 Mon Sep 17 00:00:00 2001 From: petlyh <88139840+petlyh@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:27:09 +0200 Subject: [PATCH 2/2] [Bandcamp] Throw PaidContentException on paywalled albums --- .../bandcamp/extractors/BandcampPlaylistExtractor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java index 80181e24b..451457763 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java @@ -14,8 +14,8 @@ import org.jsoup.nodes.Document; import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.downloader.Downloader; -import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.PaidContentException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; @@ -64,7 +64,7 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor { if (trackInfo.isEmpty()) { // Albums without trackInfo need to be purchased before they can be played - throw new ContentNotAvailableException("Album needs to be purchased"); + throw new PaidContentException("Album needs to be purchased"); } }