Skip to content

Commit 639ed9a

Browse files
committed
Add GeographicRestrictionException and SoundCloudGoPlusException to be able to display a different error message
1 parent beb7050 commit 639ed9a

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed
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 GeographicRestrictionException extends ParsingException {
4+
public GeographicRestrictionException(String message) {
5+
super(message);
6+
}
7+
8+
public GeographicRestrictionException(String message, Throwable cause) {
9+
super(message, cause);
10+
}
11+
}
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 SoundCloudGoPlusException extends ParsingException {
4+
public SoundCloudGoPlusException() {
5+
super("This track is a SoundCloud Go+ track");
6+
}
7+
8+
public SoundCloudGoPlusException(Throwable cause) {
9+
super("This track is a SoundCloud Go+ track", cause);
10+
}
11+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
import org.schabi.newpipe.extractor.StreamingService;
1212
import org.schabi.newpipe.extractor.downloader.Downloader;
1313
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
14-
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
1514
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
15+
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
1616
import org.schabi.newpipe.extractor.exceptions.ParsingException;
17+
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusException;
1718
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
1819
import org.schabi.newpipe.extractor.localization.DateWrapper;
1920
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
@@ -38,6 +39,7 @@
3839
import javax.annotation.Nullable;
3940

4041
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
42+
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
4143
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
4244

4345
public class SoundcloudStreamExtractor extends StreamExtractor {
@@ -53,6 +55,12 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
5355

5456
String policy = track.getString("policy", EMPTY_STRING);
5557
if (!policy.equals("ALLOW") && !policy.equals("MONETIZE")) {
58+
if (policy.equals("SNIP")) {
59+
throw new SoundCloudGoPlusException();
60+
}
61+
if (policy.equals("BLOCK")) {
62+
throw new GeographicRestrictionException("This track is not available in user's country");
63+
}
5664
throw new ContentNotAvailableException("Content not available: policy " + policy);
5765
}
5866
}

0 commit comments

Comments
 (0)