问题描述
我正在通过pyside2在Qt Creator中创建一个GUI程序,该程序可让您下载Youtube音乐。我的目标是下载播放列表时获得视频计数,例如256的x或2的x或 256的1 ,但我不知道如何。我遇到了两个问题。
[youtube:playlist] Downloading playlist PLi0XaxnSihZSnD1TNm82Y43o92r6UNEfH - add --no-playlist to just download video -5EmnQp3V48
[youtube:playlist] PLi0XaxnSihZSnD1TNm82Y43o92r6UNEfH: Downloading webpage
[download] Downloading playlist: Dance Central Songs
[youtube:playlist] PLi0XaxnSihZSnD1TNm82Y43o92r6UNEfH: Downloading page #1
[youtube:playlist] PLi0XaxnSihZSnD1TNm82Y43o92r6UNEfH: Downloading page #2
[youtube:playlist] playlist Dance Central Songs: Downloading 251 videos
[download] Downloading video **1 of 251**
[youtube] bESGLojNYSo: Downloading webpage
[download] Destination: Lady Gaga - Poker Face (Official Music Video)-bESGLojNYSo.webm
[download] 100% of 3.50MiB in 00:01
Finished
[ffmpeg] Destination: Lady Gaga - Poker Face (Official Music Video)-bESGLojNYSo.mp3
Deleting original file Lady Gaga - Poker Face (Official Music Video)-bESGLojNYSo.webm (pass -k to keep)
[download] Downloading video **2 of 251**
[youtube] E2tMV96xULk: Downloading webpage
14:03:36: C:\python38\python.exe exited with code 0
我尝试手动获取它,但是它没有用,然后我检查了youtube_dl github下载字典键,没有一个键可以获取该视频计数 1 of 256
print("Download keys:",download.keys())
Download keys: dict_keys(['status','downloaded_bytes','total_bytes','tmpfilename','filename','eta','speed','elapsed','_eta_str','_percent_str','_speed_str','_total_bytes_str'])
工作线程中的Youtube_dl代码:
def run(self):
self.main_window.progressBar.setValue(0)
self.ydl_opts = {
'format': 'bestaudio/best','noplaylist': self.main_window.playlist,'source_address': '0.0.0.0','ignoreerrors': True,'progress_hooks': [self.my_hook],'postprocessors': [{
'key': 'FFmpegExtractAudio','preferredcodec': 'mp3'
}]
}
with youtube_dl.YoutubedL(self.ydl_opts) as ydl:
ydl.download([f'{self.main_window.downloadURL.text()}'])
def my_hook(self,download):
if download["status"] == "finished":
print("Finished")
self.main_window.progresstext.setText("Ready")
if download["status"] == "downloading":
self.updateText.emit("Downloading...")
percent = download["_percent_str"]
percent = percent.replace("%","")
self.updateProgress.emit(float(percent))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)