Skip to content

Commit

Permalink
Added new exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeucelli committed Sep 2, 2024
1 parent dcb874e commit b24d3da
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/github/felipeucelli/javatube/Youtube.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ void checkAvailability() throws Exception {
} else if (reason.equals("This live stream recording is not available.")){
throw new RecordingUnavailableError(videoId());

} else if(reason.equals("The uploader has not made this video available in your country")){
throw new VideoRegionBlockedError(videoId());

} else {
throw new VideoUnavailableError(videoId());
}
Expand All @@ -261,13 +264,31 @@ void checkAvailability() throws Exception {
if (reason.equals("Sign in to confirm your age") || reason.equals("This video may be inappropriate for some users.")) {
throw new AgeRestrictedError(videoId());

} else if (reason.equals("Sign in to confirm you’re not a bot")){
throw new BotDetectionError(videoId());

}else {
throw new VideoPrivateError(videoId());
}
}
case "ERROR" -> {
if (reason.equals("Video unavailable")) {
throw new VideoUnavailableError(videoId());

}else if(reason.equals("This video is private")){
throw new VideoPrivateError(videoId());

}else if (reason.equals("This video is unavailable")){
throw new VideoUnavailableError(videoId());

}else if (reason.equals("This video has been removed by the uploader")){
throw new VideoUnavailableError(videoId());

}else if (reason.equals("This video is no longer available because the YouTube account associated with this video has been terminated.")){
throw new VideoUnavailableError(videoId());

}else {
throw new UnknownVideoError(videoId(), status, reason);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.felipeucelli.javatube.exceptions;

public class BotDetectionError extends Exception {
public BotDetectionError(String videoId) {
super(videoId + " This request was detected as a bot. Use `usePoToken=True` to view");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.felipeucelli.javatube.exceptions;

public class UnknownVideoError extends Exception{
public UnknownVideoError(String videoId, String status, String reason){
super("Unknown Video Error, VideoId: " + videoId + " Status: " + status + " Reason: " + reason);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.felipeucelli.javatube.exceptions;

public class VideoRegionBlockedError extends Exception {
public VideoRegionBlockedError(String videoId) {
super(videoId + " is not available in your region");
}
}

0 comments on commit b24d3da

Please sign in to comment.