我已经使用Python一段时间了,我决定使用pytube从Youtube下载视频,但是当我尝试下载视频时,出现属性错误。
import pytube
from pytube import *
def run():
try:
down_dir = "C:/Users/ASUS/Desktop/python projects/youtube_video_installer"
video_link = input("enter video url")
res_selected = input("enter required res")
youtube = YouTube(video_link)
title = youtube.title
print("Now downloading, " + str(title))
video = youtube.streams.get_by_resolution(res_selected)
# file_size = "FileSize : " + str(round(video.filesize / (1024 * 1024))) + "MB"
print(title)
if down_dir is not None:
video.download(output_path=down_dir, filename=str(title))
else:
video.download()
print("Download complete, " + str(title))
except Exception as e:
print("ErrorDownloadVideo | " + str(video_link))
run()
当我设置视频= youtube.streams.first()时 它可以工作,但是每当我使用.get_by_itag或.get_by_resolution指定视频时,都会出现此错误
File "C:/Users/ASUS/Desktop/python projects/youtube_video_installer/console.py", line 31, in <module>
run()
File "C:/Users/ASUS/Desktop/python projects/youtube_video_installer/console.py", line 22, in run
video.download(output_path=down_dir, filename=str(title))
AttributeError: 'NoneType' object has no attribute 'download'