我编写这段代码是为了制作Python视频下载程序:来自pytube *
# where to save
from pytube import YouTube
SAVE_PATH = "C:/Downloads"
# link of the video to be downloaded
link = input('Copy and paste your link here: ')
try:
yt: YouTube = YouTube(link)
except:
print("Connection Error")
mp4files = yt.filter('mp4')
yt.set_filename = input('What do u want to name it: ')
d_video = yt.get(mp4files[-1].extension, mp4files[-1].resolution)
try:
d_video.download(SAVE_PATH)
except:
print("Some Error!")
print('Task Completed!')在我运行它之后,它要求我输入我希望它下载的链接,就像我希望它做的那样,在我输入链接之后,它会显示以下错误:
mp4files = yt.filter('mp4')
NameError: name 'yt' is not defined我该怎么修理它?
发布于 2021-12-27 12:25:31
您可能会看到错误,因为可能有一些异常,可能您可以初始化yt = None,然后检查它是否为None,然后可以执行不同的操作。
我无法重现你的错误,但我得到了另一个错误:
Copy and paste your link here: https://www.youtube.com/watch?v=n4RjJKxsamQ
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-0d28f5939137> in <module>
12
13
---> 14 mp4files = yt.filter('mp4')
15 yt.set_filename = input('What do u want to name it: ')
16 d_video = yt.get(mp4files[-1].extension, mp4files[-1].resolution)
AttributeError: 'YouTube' object has no attribute 'filter'您可以通过查看filter来解决Pytube 'YouTube' object has no attribute 'filter'问题
https://stackoverflow.com/questions/70495354
复制相似问题