Skip to content

Commit

Permalink
Add GeographicRestrictionException and SoundCloudGoPlusException in N…
Browse files Browse the repository at this point in the history
…ewPipe Extractor to be able to display different error messages

This commit adds two new exceptions in NewPipe Extractor: GeographicRestrictionException and SoundCloudGoPlusException (which extend to ContentNotAvailableException). These exceptions allow showing different error messages to user when a content isn't available in his/her/its country (only used for now by SoundCloudStreamExtractor) or when the content is a SoundCloud Go+ track.
  • Loading branch information
AudricV committed Jan 21, 2021
1 parent beb7050 commit 6742295
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.schabi.newpipe.extractor.exceptions;

public class GeographicRestrictionException extends ContentNotAvailableException {
public GeographicRestrictionException(String message) {
super(message);
}

public GeographicRestrictionException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
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.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
Expand Down Expand Up @@ -53,6 +55,12 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr

String policy = track.getString("policy", EMPTY_STRING);
if (!policy.equals("ALLOW") && !policy.equals("MONETIZE")) {
if (policy.equals("SNIP")) {
throw new SoundCloudGoPlusException();
}
if (policy.equals("BLOCK")) {
throw new GeographicRestrictionException("This track is not available in user's country");
}
throw new ContentNotAvailableException("Content not available: policy " + policy);
}
}
Expand Down

0 comments on commit 6742295

Please sign in to comment.