1

我有以下用于下载 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)
4

2 回答 2

4

您的问题与您的代码无关。

Youtube 不再有不喜欢计数,他们只是将其删除

您只需要等待 pafy 软件包相应更新,或在本地修补软件包并自行删除该部分。

记住,至少有5 个不同的请求打开试图修复它。

于 2021-12-14T06:56:57.953 回答
0

我遇到了类似的问题,但这是由于 YouTube 最近更新了不喜欢按钮。所以代码没有问题。如果出现任何关于 youtube-dl 的操作系统错误,则需要在提示中安装它

#conda install -c forge youtube-dl #pip3 install youtube-dl

于 2021-12-25T09:46:54.317 回答