下载视频时有时会出现错误。例如,我可以尝试下载视频并且它会下载,下次我运行脚本时视频不会下载并且会抛出错误。
def search_youtube(song,randomString,playlist_name):
results = YoutubeSearch(song, max_results=1).to_dict()
for v in results:
url = 'https://www.youtube.com' + v['link']
print(url)
_filename = song
format_input = 'mp4'
format_output = 'mp3'
print("Downloading...." + ' ' + song)
time.sleep(5)
YouTube(url).streams.first().download(filename=randomString,output_path=playlist_name)