我正在为 tkinter
和 python
中的 youtube-dl 创建一个 API
并且需要知道:
- 如何从 youtube-dl 实时获取信息字典(速度、完成百分比、文件大小等)??
我试过:
import subprocess
def execute(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
# Poll process for new output until finished
while True:
nextline = process.stdout.readline()
if nextline == '' and process.poll() != None:
break
sys.stdout.write(nextline.decode('utf-8'))
sys.stdout.flush()
output = process.communicate()[0]
exitCode = process.returncode
if (exitCode == 0):
return output
else:
raise ProcessException(command, exitCode, output)
execute("youtube-dl.exe www.youtube.com/watch?v=9bZkp7q19f0 -t")
但是必须等到下载完成才能给我信息;也许有一种方法可以从 youtube-dl 源代码中获取信息。
最佳答案
尝试这样的事情:
from youtube_dl import YoutubeDL
video = "http://www.youtube.com/watch?v=BaW_jenozKc"
with YoutubeDL(youtube_dl_opts) as ydl:
info_dict = ydl.extract_info(video, download=False)
video_url = info_dict.get("url", None)
video_id = info_dict.get("id", None)
video_title = info_dict.get('title', None)
您现在可能已经明白了这一点,但它可能会对其他人有所帮助。
关于python - 如何在 python 中从 youtube-dl 获取信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23727943/