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]
我试图捕获的输出是这里的第2行:
[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的文档,说明如何从元数据中提取标题或将其作为内容包含在YoutubeDL()后面的方括号中,但我无法完全弄清楚。
这是我在python中做的第一个项目的一部分。我错过了对许多概念的理解,任何帮助都将不胜感激。
发布于 2022-01-07 15:39:23
学分:answer to问答:How to get information from youtube-dl in python ??
按以下方式修改代码:
from yt_dlp import YoutubeDL
with YoutubeDL() as ydl:
info_dict = ydl.extract_info('https://youtu.be/0KFSuoHEYm0', download=False)
video_url = info_dict.get("url", None)
video_id = info_dict.get("id", None)
video_title = info_dict.get('title', None)
print("Title: " + video_title) # <= Here, you got the video title
这是输出:
#[youtube] 0KFSuoHEYm0: Downloading webpage
#[youtube] 0KFSuoHEYm0: Downloading android player API JSON
#Title: TJ Watt gets his 4th sack of the game vs. Browns
https://stackoverflow.com/questions/70583652
复制相似问题