Pytube3,您如何选择要下载的流的ŕesourion

2024-06-26 18:08:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图建立一个YT视频下载,但我有选择一个具体的决议问题。 到目前为止,我的代码是:

from pytube import YouTube

videoUrl = str(input("Enter videoUrl"))
print("Select 1 if you want to download video or select 2 to download audio only")
def downloadVideo():
    yt = YouTube(videoUrl)
    (yt.streams.filter(progressive=True).filter(res='1080p').first().download())
    print(yt.streams)
   
def downloadAudio():
    yt=YouTube(videoUrl)
    (yt.streams.filter(only_audio=True).first().download())
    print("Download finished successfully")
userChoice =int(input())
if userChoice == 1:
    downloadVideo()
   
elif userChoice == 2:
    downloadAudio()
else:
    print("Invalid input")

运行此命令后,出现以下错误:

 File xxx, line 17, in <module>
    downloadVideo()
  File xxx, line 8, in downloadVideo
    (yt.streams.filter(progressive=True).filter(res='1080p').first().download())
AttributeError: 'NoneType' object has no attribute 'download'

这个错误有什么解决办法吗?我在谷歌上搜索,但找不到任何有用的东西,可以同时过滤和工作。提前谢谢你的帮助


Tags: totrueinputifyoutubedownloadfilteraudio