I am trying to download a YouTube video using pytube
but i get the error bellow, this error has been mentioned in stack overflow many times but almost all of them are outdated.
This and this questions are having the same problems and are left unanswered.
This question has been answered here and here but the answered appears to be outdated and so it does not work anymore.
Error:
Traceback (most recent call last):
File "C:\Users\keibo\PycharmProjects\bot2\Location\main.py", line 60, in <module>
DownloadVideo(f'{(Main.get("result")[int(choice)]).get("id")}')
File "C:\Users\keibo\PycharmProjects\bot2\Location\main.py", line 22, in DownloadVideo
video_stream = yt.streams.get_highest_resolution()
File "C:\Users\keibo\PycharmProjects\bot2\venv\lib\site-packages\pytube\__main__.py", line 296, in streams
return StreamQuery(self.fmt_streams)
File "C:\Users\keibo\PycharmProjects\bot2\venv\lib\site-packages\pytube\__main__.py", line 181, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\keibo\PycharmProjects\bot2\venv\lib\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\keibo\PycharmProjects\bot2\venv\lib\site-packages\pytube\cipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
File "C:\Users\keibo\PycharmProjects\bot2\venv\lib\site-packages\pytube\cipher.py", line 411, in get_throttling_plan
transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)
AttributeError: 'NoneType' object has no attribute 'span'
Process finished with exit code 1
Code:
def DownloadVideo(ID):
yt = YouTube(f'https://www.youtube.com/watch?v={ID}')
video_stream = yt.streams.get_highest_resolution()
video_stream.download(output_path='OutPut', filename=f'{ID}.mp4')