【问题标题】:Can I use yt-dlp to extract only one video info from a playlist?我可以使用 yt-dlp 从播放列表中仅提取一个视频信息吗?
【发布时间】:2023-01-01 02:26:12
【问题描述】:

这是我使用 Python 的代码(简化版):

import yt_dlp

YDL_OPTIONS = {
    'format': 'bestaudio*',
    'noplaylist': True,
}

with yt_dlp.YoutubeDL(YDL_OPTIONS) as ydl:
    info = ydl.extract_info(url, download=False)

当 url 指向播放列表时出现问题
(例如https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb

这是输出:

[youtube:tab] PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb: Downloading webpage
[youtube:tab] PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb: Downloading API JSON with unavailable videos
[download] Downloading playlist: C++
[youtube:tab] playlist C++: Downloading 100 videos
[download] Downloading video 1 of 100
[youtube] 18c3MTX0PK0: Downloading webpage
[youtube] 18c3MTX0PK0: Downloading android player API JSON
[download] Downloading video 2 of 100
[youtube] 1OsGXuNA5cc: Downloading webpage
[youtube] 1OsGXuNA5cc: Downloading android player API JSON
[download] Downloading video 3 of 100
[youtube] 1E_kBSka_ec: Downloading webpage
[youtube] 1E_kBSka_ec: Downloading android player API JSON
...

如您所见,'无播放列表'选项在这种情况下不起作用。

是否有选项或功能使ydl在整个播放列表中仅提取一个视频信息,例如第一个?

【问题讨论】:

    标签: python youtube youtube-dl yt-dlp


    【解决方案1】:

    noplaylist:如果有疑问,请下载单个视频而不是播放列表。

    来源:github.com/yt-dlp/yt-dlp

    您与我们分享的不是单个视频的播放列表,因此据我所知,这里没有任何疑问。

    您可以通过将'playlist_items': '1'添加到YDL_OPTIONS来请求yt_dlp仅处理播放列表的第一个视频。然后关于视频的信息在info['entries'][0]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 2014-01-19
      • 2012-06-23
      • 1970-01-01
      相关资源
      最近更新 更多