Merge pull request #243 from TeamNewPipe/fix/yt_decryption

Fix/yt decryption
This commit is contained in:
Tobias Groza 2020-01-24 02:18:40 +01:00 committed by GitHub
commit ff61e28424
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 22 deletions

View File

@ -677,8 +677,10 @@ public class YoutubeStreamExtractor extends StreamExtractor {
private static final String VERIFIED_URL_PARAMS = "&has_verified=1&bpctr=9999999999";
private final static String DECYRYPTION_SIGNATURE_FUNCTION_REGEX =
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 =
@ -697,7 +699,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final String playerUrl;
// Check if the video is age restricted
if (!doc.select("meta[property=\"og:restrictions:age\"]").isEmpty()) {
Elements e = doc.select("meta[property=\"og:restrictions:age\"]");
if (!e.isEmpty()) {
final EmbeddedInfo info = getEmbeddedInfo();
final String videoInfoUrl = getVideoInfoUrl(getId(), info.sts);
final String infoPageResponse = downloader.get(videoInfoUrl, getExtractorLocalization()).responseBody();
@ -805,7 +808,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final String sts = Parser.matchGroup1(stsPattern, embedPageContent);
return new EmbeddedInfo(playerUrl, sts);
} catch (Exception i) {
// if it failes we simply reply with no sts as then it does not seem to be necessary
// if it fails we simply reply with no sts as then it does not seem to be necessary
return new EmbeddedInfo(playerUrl, "");
}
@ -868,24 +871,22 @@ public class YoutubeStreamExtractor extends StreamExtractor {
}
private String getDecryptionFuncName(String playerCode) throws DecryptException {
String decryptionFunctionName;
// Cascading things in catch is ugly, but its faster than running a match before getting the actual name
// to se if the function can actually be found with the given regex.
// However if this cascading should propably be cleaned up somehow as it looks a bit weird.
String[] decryptionFuncNameRegexes = {
DECRYPTION_SIGNATURE_FUNCTION_REGEX_2,
DECRYPTION_SIGNATURE_FUNCTION_REGEX,
DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX,
DECRYPTION_AKAMAIZED_STRING_REGEX
};
Parser.RegexException exception = null;
for (String regex : decryptionFuncNameRegexes) {
try {
decryptionFunctionName = Parser.matchGroup1(DECYRYPTION_SIGNATURE_FUNCTION_REGEX, playerCode);
return Parser.matchGroup1(regex, playerCode);
} catch (Parser.RegexException re) {
try {
decryptionFunctionName = Parser.matchGroup1(DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX, playerCode);
} catch (Parser.RegexException re2) {
try {
decryptionFunctionName = Parser.matchGroup1(DECRYPTION_AKAMAIZED_STRING_REGEX, playerCode);
} catch (Parser.RegexException re3) {
throw new DecryptException("Could not find decrypt function with any of the given patterns.", re);
if (exception == null)
exception = re;
}
}
}
return decryptionFunctionName;
throw new DecryptException("Could not find decrypt function with any of the given patterns.", exception);
}
@Nonnull

View File

@ -67,6 +67,7 @@ public class Parser {
if (foundMatch) {
return mat.group(group);
} else {
// only pass input to exception message when it is not too long
if (input.length() > 1024) {
throw new RegexException("failed to find pattern \"" + pat.pattern());
} else {