youtubedl:如何使用选项并将输出转换为变量

2024-09-19 23:28:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试使用python而不是控制台来使用youtubedl。我正在尝试获取视频的一些信息,如可用的视频格式、标题、视频的持续时间等。除了listformats,其他选项都不起作用。所以我尝试了文档中描述的选项的不同组合。不幸的是什么都没用。我只看到listformats中的视频格式列表。另外,输出仅显示在控制台中,但我需要在变量中显示输出信息,例如video_details。在

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {
    '-v': True,
    'format': '-f',
    'print_json': True,
    'listformats': '--list-formats',
    'getfilename': '--get-filename',
    '--get-filename': True,
    '-e': True,
}

ydl = youtube_dl.YoutubeDL(ydl_opts)
video_details = ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])

Tags: import信息trueget视频youtubevideo选项