如何清除YouTube视频下载器中的“密码"错误并以mp3格式下载视频? [英] How to remove 'cipher' error from YouTube video downloader and download video in mp3 format?

查看:141
本文介绍了如何清除YouTube视频下载器中的“密码"错误并以mp3格式下载视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用pytube和tkinter在python中创建一个 YouTube视频下载器.大部分视频都可以正常下载,但在某些视频中,我收到的错误代码为'cipher'.发生这种情况时,有人可以帮忙吗?

I am trying to create a YouTube video downloader in python using pytube and tkinter. Most of the videos are getting downloaded fine but in some videos I am getting the error as 'cipher'. Can anyone help while this is happening?

我也试图以mp3格式下载,但是将'audioonly'属性设置为True会以mp4格式下载我的文件,而没有视频.但是我想要mp3中的格式.我该怎么办?

Also I am trying to download in mp3 format but setting the 'audioonly' attribute to True downloads my file in mp4 format without the video. But I want the format in mp3. How can I do so?

这是我的代码

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
            # video2 = urlField.get()

            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("Audio file is downloading")
                
                # selectVideo =yt.streams.get_audio_only()
                # new_filename= nome + '*.mp3'
                # default_filename=  nome + '*.mp4'
                # ffmpeg = ('ffmpeg -i ' %path_to_save %default_filename + new_filename)
                # subprocess.run(ffmpeg, shell=True)
                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))

            
            

            
            # yt = YouTube(url)
            # st=yt.streams.first()
            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)

推荐答案

此修复非常简单,它位于GitHub存储库中,但是由于出现了此问题,因此我将对其进行修复.这不是由于文件的工作方式引起的,而是因为YouTube将搜索方式或从密码更改为signatureCipher之类的问题而发生的.

The fix is pretty simple, it's there in the GitHub repo, but since this question came up here, this is how I fixed it. It's not due to the way your file works, it's a problem that happened because YouTube changed their search patterns or something from cipher to signatureCipher.

  • 首先,在终端中说 pip install pytube3 .

第二,转到路径- C:\ Users \< user> \ AppData \ Local \ Programs \ Python \ Python37-32 \ Lib \ site-packages \ pytube .请记住,路径会有所不同,因此将< user> 替换为Windows用户名,将 python37-32 替换为安装pytube的Python版本.

Second, go to the path - C:\Users\<user>\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\pytube. Keep in mind the path will vary so replace <user> with your Windows username and python37-32 with your Python version that you install pytube on.

第三,从上面导航的目录中打开 extract.py ,然后转到301行或搜索以下行:

Third, open extract.py from the above navigated directory and head onto line 301 or search for the line:

cipher_url = [
    parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
]

  • 现在将其替换为:
  • cipher_url = [
         parse_qs(formats[i]["signatureCipher"]) for i, data in enumerate(formats)
    ]
    

    以防在更改文件时损坏该文件,只需说出 pipuninstall pytube3 然后再次安装它,然后重复.请记住,您的导入仍将是 import pytube .

    In case you damage this file while making changes to it, just say pip uninstall pytube3 and then install it again, and repeat. Keep in mind your imports will still be import pytube.

    这篇关于如何清除YouTube视频下载器中的“密码"错误并以mp3格式下载视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆