Skip to content

Commit 5ac8062

Browse files
committed
Fix detection of YouTube's decryption function
Closes TeamNewPipe/NewPipe#3951
1 parent b4481df commit 5ac8062

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,14 @@ public String getErrorMessage() {
620620
private static final String HTTPS = "https:";
621621
private static final String DECRYPTION_FUNC_NAME = "decrypt";
622622

623-
private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX =
624-
"([\\w$]+)\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;";
625-
private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX_2 =
626-
"\\b([\\w$]{2})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;";
627-
private final static String DECRYPTION_AKAMAIZED_STRING_REGEX =
628-
"yt\\.akamaized\\.net/\\)\\s*\\|\\|\\s*.*?\\s*c\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\(";
629-
private final static String DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX =
630-
"\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\(";
623+
private final static String[] REGEXES = {
624+
"(?:\\b|[^a-zA-Z0-9$])([a-zA-Z0-9$]{2})\\s*=\\s*function\\(\\s*a\\s*\\)\\s*\\{\\s*a\\s*=\\s*a\\.split\\(\\s*\"\"\\s*\\)",
625+
"([\\w$]+)\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;",
626+
"\\b([\\w$]{2})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;",
627+
"yt\\.akamaized\\.net/\\)\\s*\\|\\|\\s*.*?\\s*c\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\(",
628+
"\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\("
629+
};
630+
;
631631

632632
private volatile String decryptionCode = "";
633633

@@ -804,20 +804,15 @@ private String decryptSignature(String encryptedSig, String decryptionCode) thro
804804
return result == null ? "" : result.toString();
805805
}
806806

807-
private String getDecryptionFuncName(String playerCode) throws DecryptException {
808-
String[] decryptionFuncNameRegexes = {
809-
DECRYPTION_SIGNATURE_FUNCTION_REGEX_2,
810-
DECRYPTION_SIGNATURE_FUNCTION_REGEX,
811-
DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX,
812-
DECRYPTION_AKAMAIZED_STRING_REGEX
813-
};
807+
private String getDecryptionFuncName(final String playerCode) throws DecryptException {
814808
Parser.RegexException exception = null;
815-
for (String regex : decryptionFuncNameRegexes) {
809+
for (final String regex : REGEXES) {
816810
try {
817811
return Parser.matchGroup1(regex, playerCode);
818812
} catch (Parser.RegexException re) {
819-
if (exception == null)
813+
if (exception == null) {
820814
exception = re;
815+
}
821816
}
822817
}
823818
throw new DecryptException("Could not find decrypt function with any of the given patterns.", exception);

0 commit comments

Comments
 (0)