问题描述
我是 wxpython 的新手。 我正在使用 pytube 库制作程序。 我可以自己下载youtube视频就好了,但是当我将其放入WXPython方法中时,UI突然挂起并且没有响应。但是当视频完成下载时,用户界面再次响应。 这是我的代码。
import wx
import pytube
from pytube import YouTube
from pytube import Playlist
import os
import time
from threading import Timer as wait
from accessible_output2 import outputs
say=outputs.auto.Auto()
speak=say.speak
app = wx.App()
class abhishek(wx.Frame):
def __init__(self):
super().__init__(None,-1,title = 'ar-developers YouTube Downloader,1.2.')
self.p = wx.Panel(self)
self.Center()
vid = wx.Button(self.p,'Download Video...')
vid.Bind(wx.EVT_BUTTON,self.video_download)
aud = wx.Button(self.p,'Download Audio...')
aud.Bind(wx.EVT_BUTTON,self.audio_download)
pv = wx.Button(self.p,'Download Playlist...')
pv.Bind(wx.EVT_BUTTON,self.playlist_download)
pa = wx.Button(self.p,'Download Playlist in Audio Format...')
pa.Bind(wx.EVT_BUTTON,self.playlist_audio_download)
self.Show()
def on_progress(self,stream=None,chunk=None,bytes_remaining=None):
self.x = '%'
self.total_size = self.video.filesize
self.bytes_downloaded = self.total_size - bytes_remaining
self.liveprogress = int(self.bytes_downloaded / self.total_size * 100)
speak(f"downloading,{self.liveprogress} {self.x}")
time.sleep(2)
def video_download(self,event):
url = wx.GetTextFromUser('Type the URL of your video','URL')
try:
youtube = pytube.YouTube(url,on_progress_callback=self.on_progress)
except:
wx.MessageBox('Please enter a valid URL','Alert')
exit()
speak(f'downloading,{youtube.title}')
self.video = youtube.streams.get_highest_resolution()
self.video.download("Downloads")
wx.MessageBox('Download Complete!','Complete')
def audio_download(self,event):
url = wx.GetTextFromUser("Enter URL of Your Video","URL")
try:
divi = YouTube(url,on_progress_callback=self.on_progress)
except:
wx.MessageBox('Please Enter a Valid URL','Error')
exit()
speak(f'downloading,{divi.title}')
self.video = divi.streams.filter(only_audio=True).first()
self.out_file = self.video.download("Downloads")
base,ext = os.path.splitext(self.out_file)
self.new_file = base + '.mp3'
os.rename(self.out_file,self.new_file)
wx.MessageBox('Download Complete!','Complete')
def playlist_download(self,event):
url = wx.GetTextFromUser("Enter the URL of your playlist. ","URL")
try:
playlist = Playlist(url)
except:
wx.MessageBox('Please Enter a Valid URL','Error')
exit()
speak('Please Wait,While We Are Downloading Your Play List')
for p in playlist.video_urls:
f = pytube.YouTube(p,on_progress_callback=self.on_progress)
speak(f'downloading,{f.title}')
self.video = f.streams.get_highest_resolution()
self.video.download("Downloads")
def playlist_audio_download(self,event):
url = wx.GetTextFromUser("Enter URL of your playlist",While We Are Downloading Your Play List')
for p in playlist.video_urls:
f = YouTube(p,{f.title}')
self.video = f.streams.filter(only_audio=True).first()
self.out_file = self.video.download("Downloads")
base,ext = os.path.splitext(self.out_file)
self.new_file = base + '.mp3'
os.rename(self.out_file,self.new_file)
abhishek()
app.MainLoop()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)