【问题标题】:ValueError: too many values to unpack (expected 2) and Tkinter/pytube problemsValueError:要解压的值太多(预期为 2)和 Tkinter/pytube 问题
【发布时间】:2020-07-30 10:10:59
【问题描述】:

我正在使用 tkinter 在 pytube 中制作 Youtube 音频下载器,用于将其放入图形界面中。它在一周前有效,但在我今天运行时无效。我不知道该怎么做,这是我希望任何人都可以帮助我的代码。 我修复了 pytube 中的密码错误,它删除了该错误以及我是新人,我不知道它是关于什么的。

python 版本:3.8

代码:

import tkinter as tk
from tkinter import filedialog
import os
from pytube import YouTube

root = tk.Tk()
root.title('Youtube to audio converter')
root.iconbitmap('000.ico')


root.geometry('600x400')

text1 = tk.Label(root, text='Youtube to audio converter:', fg="red", font=('TkDefaultFont', 18) ).place(x=150, y=0)

textEntry = tk.Entry(root, width=60)
textEntry.place(x = 120, y = 40)

text2 = tk.Label(root, text='Paste the link to the music video in the box and hit the button: ').place(x=115, y=65)

def download():
    link = textEntry.get() 
    print(link)
    yt = YouTube(link)
    t = yt.streams.filter(only_audio=True)
    t[0].download()

button = tk.Button(root, text='Download', bg='#ff3d3d', font=('TkDefaultFont', 14), command=download).place(x=250, y =100)

text3 = tk.Label(root, text='Do you want it in mp3? If so, put the name in the box below (do not forget to put the extension .mp4) \n Remember: if the file is not in the same directory it will not be converted.').place(x=30, y=150)

textEntry2 = tk.Entry(root, width=60)
textEntry2.place(x=120, y=190)

def convert():
    archivo=textEntry2.get()
    if os.path.isfile(archivo):
        os.rename(archivo, archivo + '.mp3')
    else:
        text4 = tk.Label(root, text='That is not a file or file not found', font=('TkDefaultFont', 14)).place(x=170, y=280)
    

button2 = tk.Button(root, text='Convert to .mp3', bg='#ff3d3d', font=('TkDefaultFont', 14), command=convert ).place(x=220, y =220)

root.mainloop()

错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "D:\Python3.8\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
  File "InterfaceAudioDownloader.py", line 40, in download
    yt = YouTube(link)
  File "D:\Python3.8\lib\site-packages\pytube\__main__.py", line 92, in __init__
    self.descramble()
  File "D:\Python3.8\lib\site-packages\pytube\__main__.py", line 140, in descramble
    apply_signature(self.player_config_args, fmt, self.js)
  File "D:\Python3.8\lib\site-packages\pytube\extract.py", line 225, in apply_signature
    cipher = Cipher(js=js)
  File "D:\Python3.8\lib\site-packages\pytube\cipher.py", line 31, in __init__
    var, _ = self.transform_plan[0].split(".")
ValueError: too many values to unpack (expected 2)

再次感谢您的帮助!!

【问题讨论】:

标签: python python-3.x tkinter pytube


【解决方案1】:

我记得读过 youtube 不断更改他们的 API 以防止您剥离视频的音频。还有另一个名为 youtube-dl 的软件包可以进行音频剥离。由于 youtube API 再次更改,您必须每两周更新一次软件包。这很可能是您也遇到的情况。

要回答您的问题,transform_plan[0] 的返回值可能会发生变化,或者该值所依赖的任何结构都可能发生变化。您应该回溯代码并找到更改点,或者创建回归测试以便下次轻松找到这些问题。

【讨论】:

  • 我认为这就是你所说的 YouTube 已经改变了它的 API,我已经解决了,只是安装了 pytubeX(对于那些有同样问题的人)但是 tkinter 异常仍然存在但它可以工作, 感谢您的答复。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-09
  • 2019-04-19
  • 2014-07-31
  • 2016-09-11
相关资源
最近更新 更多