hbmartin commited on
Commit
e8f51cf
·
1 Parent(s): a97679f

better JS fetching

Browse files
Files changed (2) hide show
  1. pytube/__main__.py +3 -7
  2. pytube/extract.py +1 -6
pytube/__main__.py CHANGED
@@ -131,17 +131,13 @@ class YouTube:
131
  apply_descrambler(self.vid_info, fmt)
132
  apply_descrambler(self.player_config_args, fmt)
133
 
134
- try:
135
- apply_signature(
136
- self.player_config_args, fmt, self.js # type: ignore
137
- )
138
- except TypeError:
139
  if not self.embed_html:
140
  self.embed_html = request.get(url=self.embed_url)
141
  self.js_url = extract.js_url(self.embed_html)
142
  self.js = request.get(self.js_url)
143
- assert self.js is not None
144
- apply_signature(self.player_config_args, fmt, self.js)
145
 
146
  # build instances of :class:`Stream <Stream>`
147
  self.initialize_stream_objects(fmt)
 
131
  apply_descrambler(self.vid_info, fmt)
132
  apply_descrambler(self.player_config_args, fmt)
133
 
134
+ if not self.js:
 
 
 
 
135
  if not self.embed_html:
136
  self.embed_html = request.get(url=self.embed_url)
137
  self.js_url = extract.js_url(self.embed_html)
138
  self.js = request.get(self.js_url)
139
+
140
+ apply_signature(self.player_config_args, fmt, self.js)
141
 
142
  # build instances of :class:`Stream <Stream>`
143
  self.initialize_stream_objects(fmt)
pytube/extract.py CHANGED
@@ -242,12 +242,7 @@ def apply_signature(config_args: Dict, fmt: str, js: str) -> None:
242
  logger.debug("signature found, skip decipher")
243
  continue
244
 
245
- if js is not None:
246
- signature = cipher.get_signature(ciphered_signature=stream["s"])
247
- else:
248
- # signature not present in url (line 33), need js to descramble
249
- # TypeError caught in __main__
250
- raise TypeError("JS is None")
251
 
252
  logger.debug("finished descrambling signature for itag=%s", stream["itag"])
253
  # 403 forbidden fix
 
242
  logger.debug("signature found, skip decipher")
243
  continue
244
 
245
+ signature = cipher.get_signature(ciphered_signature=stream["s"])
 
 
 
 
 
246
 
247
  logger.debug("finished descrambling signature for itag=%s", stream["itag"])
248
  # 403 forbidden fix