formatting
Browse files- pytube/cipher.py +2 -5
- pytube/extract.py +3 -2
pytube/cipher.py
CHANGED
@@ -27,7 +27,7 @@ logger = create_logger()
|
|
27 |
|
28 |
class Cipher:
|
29 |
def __init__(self, js: str):
|
30 |
-
self.transform_plan = get_transform_plan(js)
|
31 |
var, _ = self.transform_plan[0].split(".")
|
32 |
self.transform_map = get_transform_map(js, var)
|
33 |
self.js_func_regex = re.compile(r"\w+\.(\w+)\(\w,(\d+)\)")
|
@@ -37,19 +37,16 @@ class Cipher:
|
|
37 |
|
38 |
Taking the ciphered signature, applies the transform functions.
|
39 |
|
40 |
-
:param str js:
|
41 |
-
The contents of the base.js asset file.
|
42 |
:param str ciphered_signature:
|
43 |
The ciphered signature sent in the ``player_config``.
|
44 |
:rtype: str
|
45 |
:returns:
|
46 |
Decrypted signature required to download the media content.
|
47 |
-
|
48 |
"""
|
49 |
signature = list(ciphered_signature)
|
50 |
|
51 |
for js_func in self.transform_plan:
|
52 |
-
name, argument = self.parse_function(js_func)
|
53 |
signature = self.transform_map[name](signature, argument)
|
54 |
logger.debug(
|
55 |
"applied transform function\n"
|
|
|
27 |
|
28 |
class Cipher:
|
29 |
def __init__(self, js: str):
|
30 |
+
self.transform_plan: List[str] = get_transform_plan(js)
|
31 |
var, _ = self.transform_plan[0].split(".")
|
32 |
self.transform_map = get_transform_map(js, var)
|
33 |
self.js_func_regex = re.compile(r"\w+\.(\w+)\(\w,(\d+)\)")
|
|
|
37 |
|
38 |
Taking the ciphered signature, applies the transform functions.
|
39 |
|
|
|
|
|
40 |
:param str ciphered_signature:
|
41 |
The ciphered signature sent in the ``player_config``.
|
42 |
:rtype: str
|
43 |
:returns:
|
44 |
Decrypted signature required to download the media content.
|
|
|
45 |
"""
|
46 |
signature = list(ciphered_signature)
|
47 |
|
48 |
for js_func in self.transform_plan:
|
49 |
+
name, argument = self.parse_function(js_func) # type: ignore
|
50 |
signature = self.transform_map[name](signature, argument)
|
51 |
logger.debug(
|
52 |
"applied transform function\n"
|
pytube/extract.py
CHANGED
@@ -204,9 +204,10 @@ def get_ytplayer_config(html: str, age_restricted: bool = False) -> Any:
|
|
204 |
return json.loads(yt_player_config)
|
205 |
|
206 |
|
207 |
-
def get_vid_descr(html: str) -> str:
|
208 |
html_parser = PytubeHTMLParser()
|
209 |
-
|
|
|
210 |
return html_parser.vid_descr
|
211 |
|
212 |
|
|
|
204 |
return json.loads(yt_player_config)
|
205 |
|
206 |
|
207 |
+
def get_vid_descr(html: Optional[str]) -> str:
|
208 |
html_parser = PytubeHTMLParser()
|
209 |
+
if html:
|
210 |
+
html_parser.feed(html)
|
211 |
return html_parser.vid_descr
|
212 |
|
213 |
|