From 5ac80624a40f4c600ae493e66881b5bf008f0ddb Mon Sep 17 00:00:00 2001 From: TobiGr Date: Tue, 28 Jul 2020 00:44:38 +0200 Subject: [PATCH] Fix detection of YouTube's decryption function Closes TeamNewPipe/NewPipe#3951 --- .../extractors/YoutubeStreamExtractor.java | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 6812e1872d..93bd2121e8 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -620,14 +620,14 @@ public String getErrorMessage() { private static final String HTTPS = "https:"; private static final String DECRYPTION_FUNC_NAME = "decrypt"; - private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX = - "([\\w$]+)\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;"; - private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX_2 = - "\\b([\\w$]{2})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;"; - private final static String DECRYPTION_AKAMAIZED_STRING_REGEX = - "yt\\.akamaized\\.net/\\)\\s*\\|\\|\\s*.*?\\s*c\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\("; - private final static String DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX = - "\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\("; + private final static String[] REGEXES = { + "(?:\\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*\\)", + "([\\w$]+)\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;", + "\\b([\\w$]{2})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;", + "yt\\.akamaized\\.net/\\)\\s*\\|\\|\\s*.*?\\s*c\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\(", + "\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\(" + }; + ; private volatile String decryptionCode = ""; @@ -804,20 +804,15 @@ private String decryptSignature(String encryptedSig, String decryptionCode) thro return result == null ? "" : result.toString(); } - private String getDecryptionFuncName(String playerCode) throws DecryptException { - String[] decryptionFuncNameRegexes = { - DECRYPTION_SIGNATURE_FUNCTION_REGEX_2, - DECRYPTION_SIGNATURE_FUNCTION_REGEX, - DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX, - DECRYPTION_AKAMAIZED_STRING_REGEX - }; + private String getDecryptionFuncName(final String playerCode) throws DecryptException { Parser.RegexException exception = null; - for (String regex : decryptionFuncNameRegexes) { + for (final String regex : REGEXES) { try { return Parser.matchGroup1(regex, playerCode); } catch (Parser.RegexException re) { - if (exception == null) + if (exception == null) { exception = re; + } } } throw new DecryptException("Could not find decrypt function with any of the given patterns.", exception);