From 3925204658ba1e1a918137f127ff7d4ea303016f Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sat, 20 Feb 2021 14:53:57 +0100 Subject: [PATCH] Add tests and rename SoundcloudGoPlusException to SoundcloudGoPlusContentException --- .../SoundCloudGoPlusContentException.java | 11 +++++++ .../exceptions/SoundCloudGoPlusException.java | 11 ------- .../extractors/SoundcloudStreamExtractor.java | 4 +-- .../SoundcloudStreamExtractorTest.java | 28 ++++++++++++++-- .../YoutubeStreamExtractorDefaultTest.java | 32 +++++++++++++++++++ 5 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/SoundCloudGoPlusContentException.java delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/SoundCloudGoPlusException.java diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/SoundCloudGoPlusContentException.java b/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/SoundCloudGoPlusContentException.java new file mode 100644 index 000000000..0b00e1fa8 --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/SoundCloudGoPlusContentException.java @@ -0,0 +1,11 @@ +package org.schabi.newpipe.extractor.exceptions; + +public class SoundCloudGoPlusContentException extends ContentNotAvailableException { + public SoundCloudGoPlusContentException() { + super("This track is a SoundCloud Go+ track"); + } + + public SoundCloudGoPlusContentException(Throwable cause) { + super("This track is a SoundCloud Go+ track", cause); + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/SoundCloudGoPlusException.java b/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/SoundCloudGoPlusException.java deleted file mode 100644 index e3643dfb9..000000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/SoundCloudGoPlusException.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.schabi.newpipe.extractor.exceptions; - -public class SoundCloudGoPlusException extends ContentNotAvailableException { - public SoundCloudGoPlusException() { - super("This track is a SoundCloud Go+ track"); - } - - public SoundCloudGoPlusException(Throwable cause) { - super("This track is a SoundCloud Go+ track", cause); - } -} \ No newline at end of file diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java index ea1b8f303..953fa684a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java @@ -14,7 +14,7 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusException; +import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException; import org.schabi.newpipe.extractor.linkhandler.LinkHandler; import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper; @@ -46,7 +46,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor { String policy = track.getString("policy", EMPTY_STRING); if (!policy.equals("ALLOW") && !policy.equals("MONETIZE")) { if (policy.equals("SNIP")) { - throw new SoundCloudGoPlusException(); + throw new SoundCloudGoPlusContentException(); } if (policy.equals("BLOCK")) { throw new GeographicRestrictionException("This track is not available in user's country"); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java index 463a11ce3..4d9afab85 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java @@ -1,9 +1,12 @@ package org.schabi.newpipe.extractor.services.soundcloud; import org.junit.BeforeClass; +import org.junit.Test; import org.schabi.newpipe.downloader.DownloaderTestImpl; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException; +import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamType; @@ -16,12 +19,33 @@ import javax.annotation.Nullable; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; public class SoundcloudStreamExtractorTest { + private static final String SOUNDCLOUD = "https://soundcloud.com/"; + + public static class SoundcloudNotAvailable { + @Test(expected = GeographicRestrictionException.class) + public void geoRestrictedContent() throws Exception { + final String id = "one-touch"; + final String uploader = "jessglynne"; + final String url = SOUNDCLOUD + uploader + "/" + id; + final StreamExtractor extractor = SoundCloud.getStreamExtractor(url); + extractor.fetchPage(); + } + + @Test(expected = SoundCloudGoPlusContentException.class) + public void goPlusContent() throws Exception { + final String id = "places"; + final String uploader = "martinsolveig"; + final String url = SOUNDCLOUD + uploader + "/" + id; + final StreamExtractor extractor = SoundCloud.getStreamExtractor(url); + extractor.fetchPage(); + } + } public static class CreativeCommonsPlaysWellWithOthers extends DefaultStreamExtractorTest { private static final String ID = "plays-well-with-others-ep-2-what-do-an-army-of-ants-and-an-online-encyclopedia-have-in-common"; - private static final String UPLOADER = "https://soundcloud.com/wearecc"; + private static final String UPLOADER = "wearecc"; private static final int TIMESTAMP = 69; - private static final String URL = UPLOADER + "/" + ID + "#t=" + TIMESTAMP; + private static final String URL = SOUNDCLOUD + UPLOADER + "/" + ID + "#t=" + TIMESTAMP; private static StreamExtractor extractor; @BeforeClass diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java index f498a573c..5f7327b96 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java @@ -8,7 +8,11 @@ import org.schabi.newpipe.extractor.MetaInfo; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; +import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException; +import org.schabi.newpipe.extractor.exceptions.PaidContentException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.exceptions.PrivateContentException; +import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; import org.schabi.newpipe.extractor.stream.Description; @@ -59,6 +63,13 @@ public class YoutubeStreamExtractorDefaultTest { NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable")); } + @Test(expected = GeographicRestrictionException.class) + public void geoRestrictedContent() throws Exception { + final StreamExtractor extractor = + YouTube.getStreamExtractor(BASE_URL + "_PL2HJKxnOM"); + extractor.fetchPage(); + } + @Test(expected = ContentNotAvailableException.class) public void nonExistentFetch() throws Exception { final StreamExtractor extractor = @@ -72,6 +83,27 @@ public class YoutubeStreamExtractorDefaultTest { YouTube.getStreamExtractor(BASE_URL + "INVALID_ID_INVALID_ID"); extractor.fetchPage(); } + + @Test(expected = PaidContentException.class) + public void paidContent() throws Exception { + final StreamExtractor extractor = + YouTube.getStreamExtractor(BASE_URL + "ayI2iBwGdxw"); + extractor.fetchPage(); + } + + @Test(expected = PrivateContentException.class) + public void privateContent() throws Exception { + final StreamExtractor extractor = + YouTube.getStreamExtractor(BASE_URL + "8VajtrESJzA"); + extractor.fetchPage(); + } + + @Test(expected = YoutubeMusicPremiumContentException.class) + public void youtubeMusicPremiumContent() throws Exception { + final StreamExtractor extractor = + YouTube.getStreamExtractor(BASE_URL + "sMJ8bRN2dak"); + extractor.fetchPage(); + } } public static class DescriptionTestPewdiepie extends DefaultStreamExtractorTest {