【发布时间】: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)
再次感谢您的帮助!!
【问题讨论】:
-
与tkinter-exception-callback相同的问题。
标签: python python-3.x tkinter pytube