i am using the following code in order to get my video downloaded.
from pytube import YouTube
Replace the URL with the YouTube video link you want to download
video_url = “https://youtu.be/F53MPHqOmYI?si=4WhcVTZOMMmJ2xGf”
Create a YouTube object
yt = YouTube(video_url)
Print video title
print(f”Title: {yt.title}”)
Select the highest resolution stream available
stream = yt.streams.get_highest_resolution()
Download the video to the current directory
stream.download()
print(“Download completed successfully!”)
but it is throwing the following error
Traceback (most recent call last):
File “/Users/prateekvijay/vidDownloader.py”, line 5, in
audio = yt.streams.filter(only_audio=True).first()
^^^^^^^^^^
File “/opt/homebrew/lib/python3.11/site-packages/pytube/main.py”, line 296, in streams
return StreamQuery(self.fmt_streams)
^^^^^^^^^^^^^^^^
File “/opt/homebrew/lib/python3.11/site-packages/pytube/main.py”, line 176, in fmt_streams
stream_manifest = extract.apply_descrambler(self.streaming_data)
^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/lib/python3.11/site-packages/pytube/main.py”, line 160, in streaming_data
self.bypass_age_gate()
File “/opt/homebrew/lib/python3.11/site-packages/pytube/main.py”, line 257, in bypass_age_gate
innertube_response = innertube.player(self.video_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/lib/python3.11/site-packages/pytube/innertube.py”, line 448, in player
return self._call_api(endpoint, query, self.base_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/lib/python3.11/site-packages/pytube/innertube.py”, line 390, in _call_api
response = request._execute_request(
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/lib/python3.11/site-packages/pytube/request.py”, line 37, in _execute_request
return urlopen(request, timeout=timeout) # nosec
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 216, in urlopen
return opener.open(url, data, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 525, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 634, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 563, in error
return self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 496, in _call_chain
result = func(*args)
^^^^^^^^^^^
File “/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py”, line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
Can somebody please help me out?
was expecting the code to be executed and the video to get downloaded.
Prateek Vijay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.