Skip to content

Commit 3925204

Browse files
committed
Add tests and rename SoundcloudGoPlusException to SoundcloudGoPlusContentException
1 parent 771bb1a commit 3925204

5 files changed

Lines changed: 71 additions & 15 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.schabi.newpipe.extractor.exceptions;
2+
3+
public class SoundCloudGoPlusContentException extends ContentNotAvailableException {
4+
public SoundCloudGoPlusContentException() {
5+
super("This track is a SoundCloud Go+ track");
6+
}
7+
8+
public SoundCloudGoPlusContentException(Throwable cause) {
9+
super("This track is a SoundCloud Go+ track", cause);
10+
}
11+
}

extractor/src/main/java/org/schabi/newpipe/extractor/exceptions/SoundCloudGoPlusException.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1515
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
1616
import org.schabi.newpipe.extractor.exceptions.ParsingException;
17-
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusException;
17+
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
1818
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
1919
import org.schabi.newpipe.extractor.localization.DateWrapper;
2020
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
@@ -46,7 +46,7 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
4646
String policy = track.getString("policy", EMPTY_STRING);
4747
if (!policy.equals("ALLOW") && !policy.equals("MONETIZE")) {
4848
if (policy.equals("SNIP")) {
49-
throw new SoundCloudGoPlusException();
49+
throw new SoundCloudGoPlusContentException();
5050
}
5151
if (policy.equals("BLOCK")) {
5252
throw new GeographicRestrictionException("This track is not available in user's country");

extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.schabi.newpipe.extractor.services.soundcloud;
22

33
import org.junit.BeforeClass;
4+
import org.junit.Test;
45
import org.schabi.newpipe.downloader.DownloaderTestImpl;
56
import org.schabi.newpipe.extractor.NewPipe;
67
import org.schabi.newpipe.extractor.StreamingService;
8+
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
9+
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
710
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
811
import org.schabi.newpipe.extractor.stream.StreamExtractor;
912
import org.schabi.newpipe.extractor.stream.StreamType;
@@ -16,12 +19,33 @@
1619
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
1720

1821
public class SoundcloudStreamExtractorTest {
22+
private static final String SOUNDCLOUD = "https://soundcloud.com/";
23+
24+
public static class SoundcloudNotAvailable {
25+
@Test(expected = GeographicRestrictionException.class)
26+
public void geoRestrictedContent() throws Exception {
27+
final String id = "one-touch";
28+
final String uploader = "jessglynne";
29+
final String url = SOUNDCLOUD + uploader + "/" + id;
30+
final StreamExtractor extractor = SoundCloud.getStreamExtractor(url);
31+
extractor.fetchPage();
32+
}
33+
34+
@Test(expected = SoundCloudGoPlusContentException.class)
35+
public void goPlusContent() throws Exception {
36+
final String id = "places";
37+
final String uploader = "martinsolveig";
38+
final String url = SOUNDCLOUD + uploader + "/" + id;
39+
final StreamExtractor extractor = SoundCloud.getStreamExtractor(url);
40+
extractor.fetchPage();
41+
}
42+
}
1943

2044
public static class CreativeCommonsPlaysWellWithOthers extends DefaultStreamExtractorTest {
2145
private static final String ID = "plays-well-with-others-ep-2-what-do-an-army-of-ants-and-an-online-encyclopedia-have-in-common";
22-
private static final String UPLOADER = "https://soundcloud.com/wearecc";
46+
private static final String UPLOADER = "wearecc";
2347
private static final int TIMESTAMP = 69;
24-
private static final String URL = UPLOADER + "/" + ID + "#t=" + TIMESTAMP;
48+
private static final String URL = SOUNDCLOUD + UPLOADER + "/" + ID + "#t=" + TIMESTAMP;
2549
private static StreamExtractor extractor;
2650

2751
@BeforeClass

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
import org.schabi.newpipe.extractor.NewPipe;
99
import org.schabi.newpipe.extractor.StreamingService;
1010
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
11+
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
12+
import org.schabi.newpipe.extractor.exceptions.PaidContentException;
1113
import org.schabi.newpipe.extractor.exceptions.ParsingException;
14+
import org.schabi.newpipe.extractor.exceptions.PrivateContentException;
15+
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException;
1216
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
1317
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
1418
import org.schabi.newpipe.extractor.stream.Description;
@@ -59,6 +63,13 @@ public static void setUp() throws IOException {
5963
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable"));
6064
}
6165

66+
@Test(expected = GeographicRestrictionException.class)
67+
public void geoRestrictedContent() throws Exception {
68+
final StreamExtractor extractor =
69+
YouTube.getStreamExtractor(BASE_URL + "_PL2HJKxnOM");
70+
extractor.fetchPage();
71+
}
72+
6273
@Test(expected = ContentNotAvailableException.class)
6374
public void nonExistentFetch() throws Exception {
6475
final StreamExtractor extractor =
@@ -72,6 +83,27 @@ public void invalidId() throws Exception {
7283
YouTube.getStreamExtractor(BASE_URL + "INVALID_ID_INVALID_ID");
7384
extractor.fetchPage();
7485
}
86+
87+
@Test(expected = PaidContentException.class)
88+
public void paidContent() throws Exception {
89+
final StreamExtractor extractor =
90+
YouTube.getStreamExtractor(BASE_URL + "ayI2iBwGdxw");
91+
extractor.fetchPage();
92+
}
93+
94+
@Test(expected = PrivateContentException.class)
95+
public void privateContent() throws Exception {
96+
final StreamExtractor extractor =
97+
YouTube.getStreamExtractor(BASE_URL + "8VajtrESJzA");
98+
extractor.fetchPage();
99+
}
100+
101+
@Test(expected = YoutubeMusicPremiumContentException.class)
102+
public void youtubeMusicPremiumContent() throws Exception {
103+
final StreamExtractor extractor =
104+
YouTube.getStreamExtractor(BASE_URL + "sMJ8bRN2dak");
105+
extractor.fetchPage();
106+
}
75107
}
76108

77109
public static class DescriptionTestPewdiepie extends DefaultStreamExtractorTest {

0 commit comments

Comments
 (0)