【问题标题】:Pytube 'YouTube' object has no attribute 'filter'Pytube“YouTube”对象没有属性“过滤器”
【发布时间】:2020-11-03 20:54:10
【问题描述】:

我正在尝试使用 pytube 从 Youtube 下载,首先我遇到了一个常见问题,我认为这是模块本身的问题,所以我使用 github 对其进行了升级,然后此代码中出现了另一个错误:

#importing the module
from pytube import YouTube

#where to Save
save_path = "E:\Mohamed's sessions\pytube"

#link of the youtube video to be downloaded
link = "https://www.youtube.com/watch?v=w9TcErzdoTg"


#creating an object using YouTube which was imported beofre
yt = YouTube(link)  # now this yt is an object created by the class youtube and has the attribute link

#filtering out all the files with mp4 extinsion
mp4files = yt.filter("mp4")

#setting the video name
yt.set_filename("Reiner and Bertholdt Transformation scene")

#get the video with the extension and resolution passed in the get() function
d_video = yt.get(mp4files[-1].extension,mp4files[-1].resolution)

try:
    #downloading the video
    d_video.download(save_path)
except:
    print("Some Error!")
print('Task Completed!')

错误标题是: AttributeError:“YouTube”对象没有属性“过滤器” 我该如何解决?

【问题讨论】:

标签: python pytube


【解决方案1】:

这是一个更简单的代码,可以解决你遇到的问题:

from pytube import YouTube

link = "https://www.youtube.com/watch?v=w9TcErzdoTg"

yt = YouTube(link)  

try:
    yt.streams.filter(progressive = True, 
file_extension = "mp4").first().download(output_path = "E:\Mohamed's sessions\pytube", 
filename = "Reiner and Bertholdt Transformation scene")
except:
    print("Some Error!")
print('Task Completed!')

【讨论】:

    【解决方案2】:

    上述程序需要将.mp4与文件名一起添加,否则我们将无法打开文件。

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 2022-01-01
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    • 2015-12-06
    • 2018-09-13
    • 2012-12-02
    相关资源
    最近更新 更多