To open, I am running on Windows 10
I am attempting to download https://www.youtube.com/watch?v=cw2vlMK9P7U using pytube. It gives me this error:
Traceback (most recent call last):
File "c:\Users\1005447\ytdown.py", line 15, in <module>
streams = vid.streams.filter(file_extension='mp4')
^^^^^^^^^^^
File "C:\Users\1005447\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytube\__main__.py", line 296, in streams
return StreamQuery(self.fmt_streams)
^^^^^^^^^^^^^^^^
File "C:\Users\1005447\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytube\__main__.py", line 176, in fmt_streams
stream_manifest = extract.apply_descrambler(self.streaming_data)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\1005447\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytube\__main__.py", line 160, in streaming_data
self.bypass_age_gate()
File "C:\Users\1005447\AppData\Local\Programs\Python\Python312\Lib\site-packages\pytube\__main__.py", line 264, in bypass_age_gate
raise exceptions.AgeRestrictedError(self.video_id)
pytube.exceptions.AgeRestrictedError: cw2vlMK9P7U is age restricted, and can't be accessed without logging in.
Here is my source code:
import os
import pytube as pt
import time as t
urltu = input("Enter the full link to the video you wish to download --> ")
qualin = input("""Which quality do you wish to download?
Type H if you want highest
Type L if you want lowest
Type your answer here --> """)
qualin = qualin.upper()
Monostate = {"allow_ratelimiting": True}
vid = pt.YouTube(urltu)
videoid = vid.video_id
streams = vid.streams.filter(file_extension='mp4')
if qualin == "H":
stream = streams.get_by_itag(streams.first().itag)
filenamed = f"{vid.title}_highqual.mp4"
elif qualin == "L":
stream = streams.get_by_itag(streams.last())
filenamed = f"{vid.title}_lowqual.mp4"
else:
print("Invalid choice. Exiting.")
exit()
stream.download(filename=filenamed)
os.system(f'start "" "{filenamed}"')
print(f"Downloaded file. Filename is {filenamed}")
t.sleep(30)
What should I add to this file (as I cannot find innertube.py anywhere on my computer) to bypass the age gate?
Thank you for your help.
At the last line of the code, it says :
and can't be accessed without logging in.
I imagine you have to login with an account being aged higher than the restriction.