英文:
how to download videos that require age verification with pytube?
问题
我使用pytube下载和剪辑一些YouTube视频,但有些视频无法下载并要求进行年龄验证。我该如何解决?谢谢您的建议。
英文:
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
答案1
得分: 17
对于 pytube 15.0.0,即使使用了 use_oauth 选项,在流内容中也出现了 AgeRestrictedError 问题。
我只是在 innertube.py 的第 223 行将 ANDROID_MUSIC 更改为 ANDROID 作为 "client" 来解决了这个问题。
英文:
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):
答案2
得分: 2
从文档中:
对于高级用例,您可以在创建 YouTube 对象时提供一些额外的参数:
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 )
use_oauth 和 allow_oauth_cache 标志允许您授权 pytube 与 YouTube 交互,使用您的帐户,可用于绕过年龄限制或访问私人视频和播放列表。 如果 allow_oauth_cache 设置为 True,则只会提示您一次,之后 pytube 将缓存所需的令牌以代表您进行操作。否则,您将在每个需要进行身份验证的操作时再次提示。
换句话说,类似这样应该可以工作:
yt = YouTube(
'https://www.youtube.com/watch?v=B3eAMGXFw1o',
use_oauth=True,
allow_oauth_cache=True
)
# 然后以您选择的方式下载视频
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论