如何使python模块yt-dlp忽略私人视频时,下载播放列表时

发布于 2025-01-24 11:03:44 字数 1138 浏览 3 评论 0原文

我正在下载一个带有一些隐藏视频的播放列表,所以Python给我下载了Erloaderor,我想一次下载整个播放列表。是否有解决方案。 我正在尝试查看是否可以使它忽略这些隐藏的视频

我的代码:

from yt_dlp import YoutubeDL

url = 'https://www.youtube.com/playlist?list=PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs'
ydl_opts = {'format': 'mp4'}
with YoutubeDL(ydl_opts) as ydl:
    ydl.download(url)

终端中给出的错误:

Enter your URL: https://youtube.com/playlist?list=PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs
[youtube:tab] PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs: Downloading webpage
WARNING: [youtube:tab] YouTube said: INFO - 8 unavailable videos are hidden
[youtube:tab] PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs: Downloading API JSON with unavailable videos
WARNING: [youtube:tab] YouTube said: INFO - Unavailable videos will be hidden during playback
[download] Downloading playlist: English Grammar
[youtube:tab] playlist English Grammar: Downloading 52 videos
[download] Downloading video 1 of 52
[youtube] JGXK_99nc5s: Downloading webpage
[youtube] JGXK_99nc5s: Downloading android player API JSON
ERROR: [youtube] JGXK_99nc5s: Private video. Sign in if you've been granted access to this video

I'm Downloading a Playlist which has some hidden Videos so python gives me DownloadError, I want to Download the Whole Playlist at once. Is there a fix for that.
I'm trying to see if I can make it ignore those hidden videos

My Code:

from yt_dlp import YoutubeDL

url = 'https://www.youtube.com/playlist?list=PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs'
ydl_opts = {'format': 'mp4'}
with YoutubeDL(ydl_opts) as ydl:
    ydl.download(url)

Error Given in Terminal:

Enter your URL: https://youtube.com/playlist?list=PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs
[youtube:tab] PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs: Downloading webpage
WARNING: [youtube:tab] YouTube said: INFO - 8 unavailable videos are hidden
[youtube:tab] PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs: Downloading API JSON with unavailable videos
WARNING: [youtube:tab] YouTube said: INFO - Unavailable videos will be hidden during playback
[download] Downloading playlist: English Grammar
[youtube:tab] playlist English Grammar: Downloading 52 videos
[download] Downloading video 1 of 52
[youtube] JGXK_99nc5s: Downloading webpage
[youtube] JGXK_99nc5s: Downloading android player API JSON
ERROR: [youtube] JGXK_99nc5s: Private video. Sign in if you've been granted access to this video

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云裳 2025-01-31 11:03:44

基于我对文档的理解,我 think 这将做您想要的事情 - 不幸的是,我目前无法测试它,所以让我知道它是否不起作用:

import yt_dlp

ydl_opts = {
    'ignoreerrors': True
}

url = 'https://www.youtube.com/playlist?list=PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs'
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    error_code = ydl.download(url)

Based on my understanding of the documentation, I think this will do what you want - unfortunately I cannot test it at the moment, so let me know if it doesn't work:

import yt_dlp

ydl_opts = {
    'ignoreerrors': True
}

url = 'https://www.youtube.com/playlist?list=PLzMXToX8KzqhKrURIhVTJMb0v-HeDM3gs'
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    error_code = ydl.download(url)
删除会话 2025-01-31 11:03:44

我找到了一个解决方案。实际上,您使用'imageRoreRors':true。您可以将其直接传递给YouTubedl

with YoutubeDL(
        {'quiet': True, "logger": CustomLogger(), 'ignoreerrors': True}
    ) as temp:
    info_temp = temp.extract_info(link, download=False)
  • 我使用的其他选项取决于您。

  • 安静 - 只是隐藏了控制台上的详细信息。

  • CustomLogger()是我已实现的自定义记录器,因此它不会在控制台上打印日志,而是在文件上打印。

  • 下载= false是这样,它不会立即下载。我已经在其他地方实施了下载。我的脚本可以下载,也可以在不下载视频或播放列表的情况下获取有关视频或播放列表的信息。

  • 当我们使用youtubedl时,我们正在创建yt_dlp.youtubedl.youtubedl对象,然后可以使用该对象从YouTube链接中获取各种详细信息。因此temp是那个对象。

重要的是ignoreErrorYouTubedl是程序启动的位置。因此,我们通常有一个名为yt_opts的字典,其中我们指定将传递给youtubedl的键值对。因此您可以直接通过它们。

或者更好的是,您确实可以创建此yt_opts字典。所以我们会做:

link = "https://youtu.be/SaC8X-IHGiU?si=rkAN-ICgDk-7b2Em"
yt_opts({'ignoreerrors: True})

with YoutubeDL(yt_opts) as temp:
    info_temp = temp.extractinfo(link, download=False)
    # do more with info_temp eg `info_temp.get('title')` etc

I found a solution. Indeed you use 'ignoreerrors': True. and you can pass this directly to YoutubeDl.

with YoutubeDL(
        {'quiet': True, "logger": CustomLogger(), 'ignoreerrors': True}
    ) as temp:
    info_temp = temp.extract_info(link, download=False)
  • The other options I have used are up to you.

  • quiet - just hides the details on the console.

  • CustomLogger() is a custom logger i have implemented so that it doesn't print the log on the console but to a file.

  • download=False is so that it doesn't download immediately. I have implemented the download elsewhere. My script can download and as well just get information about a video or playlist without downloading it.

  • when we use YoutubeDl we are creating a yt_dlp.YoutubeDL.YoutubeDL object which then can be used to get various details from youtube links. so temp then is that object.

what is important is ignoreerror. YoutubeDl is right where the program starts. so we usually have a dictionary called yt_opts where we specify key-value pairs that will be passed to YoutubeDL. so you can pass them directly.

or better yet you can indeed create this yt_opts dictionary. so we would do:

link = "https://youtu.be/SaC8X-IHGiU?si=rkAN-ICgDk-7b2Em"
yt_opts({'ignoreerrors: True})

with YoutubeDL(yt_opts) as temp:
    info_temp = temp.extractinfo(link, download=False)
    # do more with info_temp eg `info_temp.get('title')` etc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文