I just downloaded pytube (version 11.0.1) and started with this code snippet from here:
from pytube import YouTube
YouTube('https://youtu.be/9bZkp7q19f0').streams.first().download()
which gives this error:
AttributeError Traceback (most recent call last)
<ipython-input-29-0bfa08b87614> in <module>
----> 1 YouTube('https://youtu.be/9bZkp7q19f0').streams.first().download()
~/anaconda3/lib/python3.8/site-packages/pytube/__main__.py in streams(self)
290 """
291 self.check_availability()
--> 292 return StreamQuery(self.fmt_streams)
293
294 @property
~/anaconda3/lib/python3.8/site-packages/pytube/__main__.py in fmt_streams(self)
175 # https://github.com/pytube/pytube/issues/1054
176 try:
--> 177 extract.apply_signature(stream_manifest, self.vid_info, self.js)
178 except exceptions.ExtractError:
179 # To force an update to the js file, we clear the cache and retry
~/anaconda3/lib/python3.8/site-packages/pytube/extract.py in apply_signature(stream_manifest, vid_info, js)
407
408 """
--> 409 cipher = Cipher(js=js)
410
411 for i, stream in enumerate(stream_manifest):
~/anaconda3/lib/python3.8/site-packages/pytube/cipher.py in __init__(self, js)
42
43 self.throttling_plan = get_throttling_plan(js)
---> 44 self.throttling_array = get_throttling_function_array(js)
45
46 self.calculated_n = None
~/anaconda3/lib/python3.8/site-packages/pytube/cipher.py in get_throttling_function_array(js)
321
322 array_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)
--> 323 str_array = throttling_array_split(array_raw)
324
325 converted_array = []
~/anaconda3/lib/python3.8/site-packages/pytube/parser.py in throttling_array_split(js_array)
156 # Handle functions separately. These can contain commas
157 match = func_regex.search(curr_substring)
--> 158 match_start, match_end = match.span()
159
160 function_text = find_object_from_startpoint(curr_substring, match.span()[1])
AttributeError: 'NoneType' object has no attribute 'span'
and I wonder why? Can anyone help me? I am running this snippet in an ipython console (IPython version 7.22.0) with Python 3.8.8 in a conda environment.
Found this issue, pytube v11.0.1. It's a little late for me, but if no one has submitted a fix tomorrow I'll check it out.
in C:\Python38\lib\site-packages\pytube\parser.py
Change this line:
152: func_regex = re.compile(r"function\([^)]+\)")
to this:
152: func_regex = re.compile(r"function\([^)]?\)")
The issue is that the regex expects a function with an argument, but I guess youtube added some src that includes non-paramterized functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With