How to Make Python Module yt-dlp ignore Private Videos When Downloading A Playlist

6.4k Views Asked by At

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
2

There are 2 best solutions below

0
On BEST ANSWER

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)
0
On

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