【发布时间】:2022-01-04 18:45:16
【问题描述】:
from yt_dlp import YoutubeDL
with YoutubeDL() as ydl:
ydl.download('https://youtu.be/0KFSuoHEYm0')
这是产生输出的相关代码。
我想做的是从下面的输出中获取倒数第二行,指定视频标题。
我尝试了一些变体
output = subprocess.getoutput(ydl)
还有
output = subprocess.Popen( ydl, stdout=subprocess.PIPE ).communicate()[0]
我试图捕捉的输出是这里的倒数第二行:
[youtube] 0KFSuoHEYm0: Downloading webpage
[youtube] 0KFSuoHEYm0: Downloading android player API JSON
[info] 0KFSuoHEYm0: Downloading 1 format(s): 22
[download] Destination: TJ Watt gets his 4th sack of the game vs. Browns [0KFSuoHEYm0].mp4
[download] 100% of 13.10MiB in 00:01
还有关于 yt-dlp 的文档,说明如何从元数据中提取标题或将其包含在 YoutubeDL() 后面的括号中,但我不太明白。
这是我在 python 中制作的第一个项目的一部分。我缺少对许多概念的理解,任何帮助将不胜感激。
【问题讨论】:
标签: python python-3.x youtube