Skip to content

Commit 22f8181

Browse files
committed
[YouTube] Fix JavaScript n parameter decoding function name extraction
This commits fixes extraction of the function name decoding the n parameter for HTML5 clients' streaming URLs for YouTube base JavaScript player 3400486c. Two new regexes have been added to the existing ones. All regexes and what they extract has been documented.
1 parent 480f5e2 commit 22f8181

1 file changed

Lines changed: 39 additions & 9 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingParameterUtils.java

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,54 @@ final class YoutubeThrottlingParameterUtils {
2626

2727
private static final String ARRAY_ACCESS_REGEX = "\\[(\\d+)]";
2828

29-
/**
30-
* The first regex matches this, where we want BDa:
31-
* <p>
32-
* (b=String.fromCharCode(110),c=a.get(b))&&(c=<strong>BDa</strong><strong>[0]</strong>(c)
33-
* <p>
34-
* Array access is optional, but needs to be handled, since the actual function is inside the
35-
* array.
36-
*/
3729
// CHECKSTYLE:OFF
3830
private static final Pattern[] DEOBFUSCATION_FUNCTION_NAME_REGEXES = {
31+
32+
/*
33+
* The first regex matches the following text, where we want rDa and the array index
34+
* accessed:
35+
*
36+
* a.D&&(b="nn"[+a.D],c=a.get(b))&&(c=rDa[0](c),a.set(b,c),rDa.length||rma("")
37+
*/
38+
Pattern.compile(SINGLE_CHAR_VARIABLE_REGEX + "+=\"nn\"\\[\\+"
39+
+ SINGLE_CHAR_VARIABLE_REGEX + "+\\." + SINGLE_CHAR_VARIABLE_REGEX + "+],"
40+
+ SINGLE_CHAR_VARIABLE_REGEX + "+=" + SINGLE_CHAR_VARIABLE_REGEX
41+
+ "+\\.get\\(" + SINGLE_CHAR_VARIABLE_REGEX + "+\\)\\)&&\\("
42+
+ SINGLE_CHAR_VARIABLE_REGEX + "+=(" + SINGLE_CHAR_VARIABLE_REGEX
43+
+ "+)\\[(\\d+)]"),
44+
45+
/*
46+
* The second regex matches the following text, where we want rma:
47+
*
48+
* a.D&&(b="nn"[+a.D],c=a.get(b))&&(c=rDa[0](c),a.set(b,c),rDa.length||rma("")
49+
*/
50+
Pattern.compile(SINGLE_CHAR_VARIABLE_REGEX + "+=\"nn\"\\[\\+"
51+
+ SINGLE_CHAR_VARIABLE_REGEX + "+\\." + SINGLE_CHAR_VARIABLE_REGEX + "+],"
52+
+ SINGLE_CHAR_VARIABLE_REGEX + "+=" + SINGLE_CHAR_VARIABLE_REGEX + "+\\.get\\("
53+
+ SINGLE_CHAR_VARIABLE_REGEX + "+\\)\\).+\\|\\|(" + SINGLE_CHAR_VARIABLE_REGEX
54+
+ "+)\\(\"\"\\)"),
55+
56+
/*
57+
* The third regex matches the following text, where we want BDa and the array index
58+
* accessed:
59+
*
60+
* (b=String.fromCharCode(110),c=a.get(b))&&(c=BDa[0](c)
61+
*/
3962
Pattern.compile("\\(" + SINGLE_CHAR_VARIABLE_REGEX + "=String\\.fromCharCode\\(110\\),"
4063
+ SINGLE_CHAR_VARIABLE_REGEX + "=" + SINGLE_CHAR_VARIABLE_REGEX + "\\.get\\("
4164
+ SINGLE_CHAR_VARIABLE_REGEX + "\\)\\)" + "&&\\(" + SINGLE_CHAR_VARIABLE_REGEX
4265
+ "=(" + FUNCTION_NAME_REGEX + ")" + "(?:" + ARRAY_ACCESS_REGEX + ")?\\("
4366
+ SINGLE_CHAR_VARIABLE_REGEX + "\\)"),
67+
68+
/*
69+
* The fourth regex matches the following text, where we want Yva and the array index
70+
* accessed:
71+
*
72+
* .get("n"))&&(b=Yva[0](b)
73+
*/
4474
Pattern.compile("\\.get\\(\"n\"\\)\\)&&\\(" + SINGLE_CHAR_VARIABLE_REGEX
4575
+ "=(" + FUNCTION_NAME_REGEX + ")(?:" + ARRAY_ACCESS_REGEX + ")?\\("
46-
+ SINGLE_CHAR_VARIABLE_REGEX + "\\)"),
76+
+ SINGLE_CHAR_VARIABLE_REGEX + "\\)")
4777
};
4878
// CHECKSTYLE:ON
4979

0 commit comments

Comments
 (0)