我有以下用于下载 youtube 视频的代码。我会自动检测它是播放列表还是单个视频。然而突然之间它给出了上述错误。可能是什么问题?
import pafy
from log import *
import tkinter.filedialog
import pytube
url = input("Enter url :")
directory = tkinter.filedialog.askdirectory()
def single_url(url,directory):
print("==================================================================================================================")
video = pafy.new(url)
print(url)
print(video.title)
#logs(video.title,url)
file_object = open(directory+"/links.log", "a")
file_object.write(video.title +' '+ url + '\n')
file_object.close()
print('Rating :',video.rating,', Duration :',video.duration,', Likes :',video.likes, ', Dislikes : ', video.dislikes)
#print(video.description)
best = video.getbest()
print(best.resolution, best.extension)
best.download(quiet=False, filepath=directory+'/'+video.title+"." + best.extension)
print("saved at :", directory, " directory")
print("==================================================================================================================")
def playlist_func(url,directory):
try:
playlist = pytube.Playlist(url)
file_object = open(directory+"/links.log", "a")
file_object.write('Playlist Url :'+ url + '\n')
file_object.close()
print('There are {0}'.format(len(playlist.video_urls)))
for url in playlist.video_urls:
single_url(url,directory)
except:
single_url(url,directory)
playlist_func(url,directory)