Merge pull request #313 from johnberroa/fix/regexmatcherror
Browse files- pytube/cipher.py +2 -1
- pytube/helpers.py +47 -21
pytube/cipher.py
CHANGED
@@ -35,7 +35,8 @@ def get_initial_function_name(js):
|
|
35 |
|
36 |
"""
|
37 |
# c&&d.set("signature", EE(c));
|
38 |
-
pattern = r'
|
|
|
39 |
logger.debug('finding initial function name')
|
40 |
return regex_search(pattern, js, group=1)
|
41 |
|
|
|
35 |
|
36 |
"""
|
37 |
# c&&d.set("signature", EE(c));
|
38 |
+
pattern = [r'yt\.akamaized\.net/\)\s*\|\|\s*.*?\s*c\s*&&\s*d\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
|
39 |
+
r'\.sig\|\|(?P<sig>[a-zA-Z0-9$]+)\(', r'\bc\s*&&\s*d\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(']
|
40 |
logger.debug('finding initial function name')
|
41 |
return regex_search(pattern, js, group=1)
|
42 |
|
pytube/helpers.py
CHANGED
@@ -31,29 +31,55 @@ def regex_search(pattern, string, groups=False, group=None, flags=0):
|
|
31 |
:returns:
|
32 |
Substring pattern matches.
|
33 |
"""
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
else:
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
),
|
50 |
-
)
|
51 |
-
if groups:
|
52 |
-
return results.groups()
|
53 |
-
elif group is not None:
|
54 |
-
return results.group(group)
|
55 |
else:
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
|
59 |
def apply_mixin(dct, key, func, *args, **kwargs):
|
|
|
31 |
:returns:
|
32 |
Substring pattern matches.
|
33 |
"""
|
34 |
+
if type(pattern) == list:
|
35 |
+
for p in pattern:
|
36 |
+
regex = re.compile(p, flags)
|
37 |
+
results = regex.search(string)
|
38 |
+
if not results:
|
39 |
+
raise RegexMatchError(
|
40 |
+
'regex pattern ({pattern}) had zero matches'
|
41 |
+
.format(pattern=p),
|
42 |
+
)
|
43 |
+
else:
|
44 |
+
logger.debug(
|
45 |
+
'finished regex search: %s',
|
46 |
+
pprint.pformat(
|
47 |
+
{
|
48 |
+
'pattern': p,
|
49 |
+
'results': results.group(0),
|
50 |
+
}, indent=2,
|
51 |
+
),
|
52 |
+
)
|
53 |
+
if groups:
|
54 |
+
return results.groups()
|
55 |
+
elif group is not None:
|
56 |
+
return results.group(group)
|
57 |
+
else:
|
58 |
+
return results
|
59 |
else:
|
60 |
+
regex = re.compile(pattern, flags)
|
61 |
+
results = regex.search(string)
|
62 |
+
if not results:
|
63 |
+
raise RegexMatchError(
|
64 |
+
'regex pattern ({pattern}) had zero matches'
|
65 |
+
.format(pattern=pattern),
|
66 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
else:
|
68 |
+
logger.debug(
|
69 |
+
'finished regex search: %s',
|
70 |
+
pprint.pformat(
|
71 |
+
{
|
72 |
+
'pattern': pattern,
|
73 |
+
'results': results.group(0),
|
74 |
+
}, indent=2,
|
75 |
+
),
|
76 |
+
)
|
77 |
+
if groups:
|
78 |
+
return results.groups()
|
79 |
+
elif group is not None:
|
80 |
+
return results.group(group)
|
81 |
+
else:
|
82 |
+
return results
|
83 |
|
84 |
|
85 |
def apply_mixin(dct, key, func, *args, **kwargs):
|