require group parameter
Browse files- pytube/cipher.py +2 -1
- pytube/helpers.py +8 -14
- tests/test_helpers.py +2 -3
pytube/cipher.py
CHANGED
@@ -16,6 +16,7 @@ signature and decoding it.
|
|
16 |
|
17 |
import re
|
18 |
from itertools import chain
|
|
|
19 |
|
20 |
from pytube.exceptions import RegexMatchError
|
21 |
from pytube.helpers import regex_search, create_logger
|
@@ -58,7 +59,7 @@ def get_initial_function_name(js: str) -> str:
|
|
58 |
raise RegexMatchError("get_initial_function_name not found")
|
59 |
|
60 |
|
61 |
-
def get_transform_plan(js: str) -> str:
|
62 |
"""Extract the "transform plan".
|
63 |
|
64 |
The "transform plan" is the functions that the ciphered signature is
|
|
|
16 |
|
17 |
import re
|
18 |
from itertools import chain
|
19 |
+
from typing import List
|
20 |
|
21 |
from pytube.exceptions import RegexMatchError
|
22 |
from pytube.helpers import regex_search, create_logger
|
|
|
59 |
raise RegexMatchError("get_initial_function_name not found")
|
60 |
|
61 |
|
62 |
+
def get_transform_plan(js: str) -> List[str]:
|
63 |
"""Extract the "transform plan".
|
64 |
|
65 |
The "transform plan" is the functions that the ciphered signature is
|
pytube/helpers.py
CHANGED
@@ -12,9 +12,7 @@ from pytube.exceptions import RegexMatchError
|
|
12 |
logger = logging.getLogger(__name__)
|
13 |
|
14 |
|
15 |
-
def regex_search(
|
16 |
-
pattern: str, string: str, group: Optional[int] = None,
|
17 |
-
):
|
18 |
"""Shortcut method to search a string for a given pattern.
|
19 |
|
20 |
:param str pattern:
|
@@ -34,17 +32,13 @@ def regex_search(
|
|
34 |
raise RegexMatchError(
|
35 |
"regex pattern ({pattern}) had zero matches".format(pattern=pattern),
|
36 |
)
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
if group is not None:
|
45 |
-
return results.group(group)
|
46 |
-
else:
|
47 |
-
return results
|
48 |
|
49 |
|
50 |
def apply_mixin(dct, key, func, *args, **kwargs):
|
|
|
12 |
logger = logging.getLogger(__name__)
|
13 |
|
14 |
|
15 |
+
def regex_search(pattern: str, string: str, group: int) -> str:
|
|
|
|
|
16 |
"""Shortcut method to search a string for a given pattern.
|
17 |
|
18 |
:param str pattern:
|
|
|
32 |
raise RegexMatchError(
|
33 |
"regex pattern ({pattern}) had zero matches".format(pattern=pattern),
|
34 |
)
|
35 |
+
|
36 |
+
logger.debug(
|
37 |
+
"finished regex search: %s",
|
38 |
+
pprint.pformat({"pattern": pattern, "results": results.group(0),}, indent=2,),
|
39 |
+
)
|
40 |
+
|
41 |
+
return results.group(group)
|
|
|
|
|
|
|
|
|
42 |
|
43 |
|
44 |
def apply_mixin(dct, key, func, *args, **kwargs):
|
tests/test_helpers.py
CHANGED
@@ -7,12 +7,11 @@ from pytube.exceptions import RegexMatchError
|
|
7 |
|
8 |
def test_regex_search_no_match():
|
9 |
with pytest.raises(RegexMatchError):
|
10 |
-
helpers.regex_search("^a$", "")
|
11 |
|
12 |
|
13 |
def test_regex_search():
|
14 |
-
|
15 |
-
assert helpers.regex_search("^a$", "a") is not None
|
16 |
|
17 |
|
18 |
def test_safe_filename():
|
|
|
7 |
|
8 |
def test_regex_search_no_match():
|
9 |
with pytest.raises(RegexMatchError):
|
10 |
+
helpers.regex_search("^a$", "", group=0)
|
11 |
|
12 |
|
13 |
def test_regex_search():
|
14 |
+
assert helpers.regex_search("^a$", "a", group=0) == "a"
|
|
|
15 |
|
16 |
|
17 |
def test_safe_filename():
|