Skip to content

Commit cf18cdb

Browse files
authored
Merge pull request #329 from wb9688/decryption-regexes
Add more decryption function regexes
2 parents 0b4977b + 384d6ac commit cf18cdb

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,21 @@ public String getErrorMessage() {
583583
private static final String HTTPS = "https:";
584584
private static final String DECRYPTION_FUNC_NAME = "decrypt";
585585

586-
private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX =
587-
"([\\w$]+)\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;";
588-
private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX_2 =
589-
"\\b([\\w$]{2})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;";
590-
private final static String DECRYPTION_AKAMAIZED_STRING_REGEX =
591-
"yt\\.akamaized\\.net/\\)\\s*\\|\\|\\s*.*?\\s*c\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\(";
592-
private final static String DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX =
593-
"\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\(";
586+
private final static String[] REGEXES = {
587+
"\\b[cs]\\s*&&\\s*[adf]\\.set\\([^,]+\\s*,\\s*encodeURIComponent\\s*\\(\\s*([a-zA-Z0-9$]+)\\(",
588+
"\\b[a-zA-Z0-9]+\\s*&&\\s*[a-zA-Z0-9]+\\.set\\([^,]+\\s*,\\s*encodeURIComponent\\s*\\(\\s*([a-zA-Z0-9$]+)\\(",
589+
"\\b([a-zA-Z0-9$]{2})\\s*=\\s*function\\(\\s*a\\s*\\)\\s*\\{\\s*a\\s*=\\s*a\\.split\\(\\s*\"\"\\s*\\)",
590+
"([a-zA-Z0-9$]+)\\s*=\\s*function\\(\\s*a\\s*\\)\\s*\\{\\s*a\\s*=\\s*a\\.split\\(\\s*\"\"\\s*\\)",
591+
// Obsolete patterns
592+
"[\"']signature[\"']\\s*,\\s*([a-zA-Z0-9$]+)\\(",
593+
"\\.sig\\|\\|([a-zA-Z0-9$]+)\\(",
594+
"yt\\.akamaized\\.net/\\)\\s*\\|\\|\\s*.*?\\s*[cs]\\s*&&\\s*[adf]\\.set\\([^,]+\\s*,\\s*(?:encodeURIComponent\\s*\\()?\\s*([a-zA-Z0-9$]+)\\(",
595+
"\\b[cs]\\s*&&\\s*[adf]\\.set\\([^,]+\\s*,\\s*([a-zA-Z0-9$]+)\\(",
596+
"\\b[a-zA-Z0-9]+\\s*&&\\s*[a-zA-Z0-9]+\\.set\\([^,]+\\s*,\\s*([a-zA-Z0-9$]+)\\(",
597+
"\\bc\\s*&&\\s*a\\.set\\([^,]+\\s*,\\s*\\([^)]*\\)\\s*\\(\\s*([a-zA-Z0-9$]+)\\(",
598+
"\\bc\\s*&&\\s*[a-zA-Z0-9]+\\.set\\([^,]+\\s*,\\s*\\([^)]*\\)\\s*\\(\\s*([a-zA-Z0-9$]+)\\(",
599+
"\\bc\\s*&&\\s*[a-zA-Z0-9]+\\.set\\([^,]+\\s*,\\s*\\([^)]*\\)\\s*\\(\\s*([a-zA-Z0-9$]+)\\("
600+
};
594601

595602
private volatile String decryptionCode = "";
596603

@@ -767,20 +774,15 @@ private String decryptSignature(String encryptedSig, String decryptionCode) thro
767774
return result == null ? "" : result.toString();
768775
}
769776

770-
private String getDecryptionFuncName(String playerCode) throws DecryptException {
771-
String[] decryptionFuncNameRegexes = {
772-
DECRYPTION_SIGNATURE_FUNCTION_REGEX_2,
773-
DECRYPTION_SIGNATURE_FUNCTION_REGEX,
774-
DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX,
775-
DECRYPTION_AKAMAIZED_STRING_REGEX
776-
};
777+
private String getDecryptionFuncName(final String playerCode) throws DecryptException {
777778
Parser.RegexException exception = null;
778-
for (String regex : decryptionFuncNameRegexes) {
779+
for (final String regex : REGEXES) {
779780
try {
780781
return Parser.matchGroup1(regex, playerCode);
781782
} catch (Parser.RegexException re) {
782-
if (exception == null)
783+
if (exception == null) {
783784
exception = re;
785+
}
784786
}
785787
}
786788
throw new DecryptException("Could not find decrypt function with any of the given patterns.", exception);

0 commit comments

Comments
 (0)