Use final in exceptions and add AgeRestrictedException

AgeRestrictedException will be thrown only if the reason message equals to "Sign in to confirm your age" and if the age limit is 18.
This commit is contained in:
TiA4f8R 2021-02-23 19:03:34 +01:00
parent 22e6f33f0a
commit 448b68700c
No known key found for this signature in database
GPG Key ID: E6D3E7F5949450DD
13 changed files with 34 additions and 21 deletions

View File

@ -0,0 +1,10 @@
package org.schabi.newpipe.extractor.exceptions;
public class AgeRestrictedContentException extends ContentNotAvailableException {
public AgeRestrictedContentException(final String message) {
super(message);
}
public AgeRestrictedContentException(final String message, final Throwable cause) {
super(message, cause);
}
}

View File

@ -1,11 +1,11 @@
package org.schabi.newpipe.extractor.exceptions;
public class ContentNotAvailableException extends ParsingException {
public ContentNotAvailableException(String message) {
public ContentNotAvailableException(final String message) {
super(message);
}
public ContentNotAvailableException(String message, Throwable cause) {
public ContentNotAvailableException(final String message, final Throwable cause) {
super(message, cause);
}
}

View File

@ -1,11 +1,11 @@
package org.schabi.newpipe.extractor.exceptions;
public class ContentNotSupportedException extends ParsingException {
public ContentNotSupportedException(String message) {
public ContentNotSupportedException(final String message) {
super(message);
}
public ContentNotSupportedException(String message, Throwable cause) {
public ContentNotSupportedException(final String message, final Throwable cause) {
super(message, cause);
}
}

View File

@ -21,15 +21,15 @@ package org.schabi.newpipe.extractor.exceptions;
*/
public class ExtractionException extends Exception {
public ExtractionException(String message) {
public ExtractionException(final String message) {
super(message);
}
public ExtractionException(Throwable cause) {
public ExtractionException(final Throwable cause) {
super(cause);
}
public ExtractionException(String message, Throwable cause) {
public ExtractionException(final String message, final Throwable cause) {
super(message, cause);
}
}

View File

@ -21,11 +21,11 @@ package org.schabi.newpipe.extractor.exceptions;
*/
public class FoundAdException extends ParsingException {
public FoundAdException(String message) {
public FoundAdException(final String message) {
super(message);
}
public FoundAdException(String message, Throwable cause) {
public FoundAdException(final String message, final Throwable cause) {
super(message, cause);
}
}

View File

@ -1,11 +1,11 @@
package org.schabi.newpipe.extractor.exceptions;
public class GeographicRestrictionException extends ContentNotAvailableException {
public GeographicRestrictionException(String message) {
public GeographicRestrictionException(final String message) {
super(message);
}
public GeographicRestrictionException(String message, Throwable cause) {
public GeographicRestrictionException(final String message, final Throwable cause) {
super(message, cause);
}
}

View File

@ -1,11 +1,11 @@
package org.schabi.newpipe.extractor.exceptions;
public class PaidContentException extends ContentNotAvailableException {
public PaidContentException(String message) {
public PaidContentException(final String message) {
super(message);
}
public PaidContentException(String message, Throwable cause) {
public PaidContentException(final String message, final Throwable cause) {
super(message, cause);
}
}

View File

@ -22,11 +22,11 @@ package org.schabi.newpipe.extractor.exceptions;
public class ParsingException extends ExtractionException {
public ParsingException(String message) {
public ParsingException(final String message) {
super(message);
}
public ParsingException(String message, Throwable cause) {
public ParsingException(final String message, final Throwable cause) {
super(message, cause);
}
}
}

View File

@ -1,11 +1,11 @@
package org.schabi.newpipe.extractor.exceptions;
public class PrivateContentException extends ContentNotAvailableException {
public PrivateContentException(String message) {
public PrivateContentException(final String message) {
super(message);
}
public PrivateContentException(String message, Throwable cause) {
public PrivateContentException(final String message, final Throwable cause) {
super(message, cause);
}
}

View File

@ -23,7 +23,7 @@ package org.schabi.newpipe.extractor.exceptions;
public class ReCaptchaException extends ExtractionException {
private String url;
public ReCaptchaException(String message, String url) {
public ReCaptchaException(final String message, final String url) {
super(message);
this.url = url;
}

View File

@ -5,7 +5,7 @@ public class SoundCloudGoPlusContentException extends ContentNotAvailableExcepti
super("This track is a SoundCloud Go+ track");
}
public SoundCloudGoPlusContentException(Throwable cause) {
public SoundCloudGoPlusContentException(final Throwable cause) {
super("This track is a SoundCloud Go+ track", cause);
}
}

View File

@ -5,7 +5,7 @@ public class YoutubeMusicPremiumContentException extends ContentNotAvailableExce
super("This video is a YouTube Music Premium video");
}
public YoutubeMusicPremiumContentException(Throwable cause) {
public YoutubeMusicPremiumContentException(final Throwable cause) {
super("This video is a YouTube Music Premium video", cause);
}
}

View File

@ -16,6 +16,7 @@ import org.schabi.newpipe.extractor.MetaInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
@ -735,6 +736,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
if (message != null && message.equals("This is a private video. Please sign in to verify that you may see it.")) {
throw new PrivateContentException("This video is private.");
}
} else if (reason.equals("Sign in to confirm your age") && getAgeLimit() == 18) {
throw new AgeRestrictedContentException("This age-restricted video cannot be watched.");
}
}
if (status.toLowerCase().equals("unplayable")) {