如何在python中删除pytube中的“资产”错误?

2024-10-01 07:39:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python中的pytube制作了一个youtube视频下载程序。它以前工作正常,但有时会出现“资产”错误。我试了很多,但解决不了。我也尝试过搜索错误解决方案,但我找不到类似的东西

这是我的密码

def startDownload(url):
    global file_size
    path_to_save = askdirectory()
    if path_to_save is None:
        return

    try:
            global MaxFileSize, fileSizeInBytes
            choice = youtubeChoicesLabel.get()
            url=urlField.get()
            yt = YouTube(url)
            nome = yt.title
            if (choice == download_choices[1]):
                print("720p video is downloading")
                selectVideo = yt.streams.filter(progressive=True, file_extension='mp4').first()
                
            elif (choice == download_choices[2]):
                print("144 video is downloading")
                selectVideo = yt.streams.filter(progressive=True, file_extension='mp4').last()

                selectVideo = yt.streams.filter(only_audio=True).first()
                
                
            elif (choice == download_choices[0]):
                return

            
                fileSizeInBytes = selectVideo.filesize
                MaxFileSize = fileSizeInBytes/1024000
                MB =str(MaxFileSize)+ "MB"
                print("File Size = : {:00.000f}".format (MaxFileSize))

            st= selectVideo
            yt.register_on_complete_callback(complete_download)
            yt.register_on_progress_callback(progress_download)
            file_size=st.filesize
            st.download(output_path=path_to_save)

    except Exception as e:
        print(e)

download_choices = ["----Download Type----",
                    "Mp4  720p",
                    "Mp4  144p",
                    # "Video  3gp",
                    "Audio  Mp3"]

def btnClicked():    

    try:
        downloadBtn['text'] = "Please wait....."
        downloadBtn["bg"] = "red"
        downloadBtn["fg"] ="white"
        downloadBtn['state']= 'disabled'
        url=urlField.get()
        if url == '':
            showinfo("Message","Please input a url of the video.....")
            return
        print(url)
        
        thread= Thread(target=startDownload,args=(url,))
        thread.start()
    except Exception as e:
        print(e)

这是我的错误

soham@LAPTOP-FJLV55TK MINGW64 ~
y"python "e:/python projects/YOUTUBE VIDEO DOWNLOADER/YOUTUBE_VIDEO_DOWNLOADER.py
e:/python projects/YOUTUBE VIDEO DOWNLOADER/YOUTUBE_VIDEO_DOWNLOADER.py
https://www.youtube.com/watch?v=rTuxUAuJRyY
'assets'

Tags: pathurlyoutubedownloadvideo错误downloaderfile