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

时间:2021-01-03 00:44:29

标签: python pytube

我正在尝试构建 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'

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

0 个答案:

没有答案