Skip to content

Commit 3e57052

Browse files
committed
[YouTube] Add custom error for "Sign in to confirm ..."
1 parent 260ba47 commit 3e57052

2 files changed

Lines changed: 20 additions & 1 deletion

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+
/**
4+
* Content can't be extracted because the service requires logging in to confirm the user is not a
5+
* bot. Can usually only be solvable by changing IP (e.g. in the case of YouTube).
6+
*/
7+
public class SignInConfirmNotBotException extends ParsingException {
8+
public SignInConfirmNotBotException(final String message) {
9+
super(message);
10+
}
11+
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.schabi.newpipe.extractor.exceptions.ParsingException;
5454
import org.schabi.newpipe.extractor.exceptions.PrivateContentException;
5555
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException;
56+
import org.schabi.newpipe.extractor.exceptions.SignInConfirmNotBotException;
5657
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
5758
import org.schabi.newpipe.extractor.localization.ContentCountry;
5859
import org.schabi.newpipe.extractor.localization.DateWrapper;
@@ -901,7 +902,14 @@ private static void checkPlayabilityStatus(@Nonnull final JsonObject playability
901902
}
902903
}
903904

904-
throw new ContentNotAvailableException("Got error: \"" + reason + "\"");
905+
// "Sign in to confirm that you're not a bot"
906+
if (reason != null && reason.contains("a bot")) {
907+
throw new SignInConfirmNotBotException(
908+
"YouTube probably temporarily blocked this IP, got error "
909+
+ status + ": \"" + reason + "\"");
910+
}
911+
912+
throw new ContentNotAvailableException("Got error " + status + ": \"" + reason + "\"");
905913
}
906914

907915
private void fetchHtml5Client(@Nonnull final Localization localization,

0 commit comments

Comments
 (0)