I download and clip some youtube videos with pytube but some videos are not downloading and asking for age verification. How can I solve this? Thanks for your advice
-
Does this answer your question? [Python youtube\_dl does not allow to download age-restricted videos](https://stackoverflow.com/questions/73088233/python-youtube-dl-does-not-allow-to-download-age-restricted-videos) – Gameplay Mar 20 '23 at 15:02
-
I was using pytube but I will change it according to your advice and I will share the update. thank you @Gameplay – byhite Mar 20 '23 at 15:13
2 Answers
For pytube 15.0.0 I had the AgeRestrictedError in streams contents even using the use_oauth option.
I fixed the problem only changing ANDROID_MUSIC with ANDROID as "client" at line 223 of innertube.py:
def __init__(self, client='ANDROID_MUSIC', use_oauth=False, allow_cache=True):
def __init__(self, client='ANDROID', use_oauth=False, allow_cache=True):

- 550
- 5
- 7
From the documentation:
For advanced use cases, you can provide some additional arguments when you create a YouTube object:
>>> yt = YouTube( 'http://youtube.com/watch?v=2lAe1cqCOXo', on_progress_callback=progress_func, on_complete_callback=complete_func, proxies=my_proxies, use_oauth=False, allow_oauth_cache=True )
The use_oauth and allow_oauth_cache flags allow you to authorize pytube to interact with YouTube using your account, and can be used to bypass age restrictions or access private videos and playlists. If allow_oauth_cache is set to True, you should only be prompted to do so once, after which point pytube will cache the tokens it needs to act on your behalf. Otherwise, you will be prompted again for each action that requires you to be authenticated.
So, in other words, something like this should work:
yt = YouTube(
'https://www.youtube.com/watch?v=B3eAMGXFw1o',
use_oauth=True,
allow_oauth_cache=True
)
# then download the video in whichever way you choose fit

- 7,785
- 2
- 14
- 34
-
1yeah still not sure how to get work with it for age restriction... Sad because pytube is great but there must be something I'm missing or not understanding. – boardkeystown Aug 11 '23 at 03:47
-