使用pytube下载youtube视频时出现属性错误

问题描述

我已经使用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'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...