question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option max_downloads not working on embed yt-dlp

See original GitHub issue

Checklist

  • I’m reporting a bug unrelated to a specific site
  • I’ve verified that I’m running yt-dlp version 2022.02.04. (update instructions)
  • I’ve checked that all provided URLs are alive and playable in a browser
  • I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
  • I’ve searched the bugtracker for similar issues including closed ones. DO NOT post duplicates
  • I’ve read the guidelines for opening an issue

Description

When embeding yt-dlp in my program, I try to limit the number of downloads from a playlist by using the max_downloads option.

On a shell, the feature work pretty well but when I’m using it on my Python code, the playlist is fully downloaded instead of the X elements as expected.

See a reproducer:

from yt_dlp import YoutubeDL

def main():
    YTDL_FORMAT_OPTION: dict = {
        "format": "bestaudio/best",
        'max_downloads': 5,
        "compat_opts": "no-youtube-unavailable-videos",
        "verbose": True,
    }
    with YoutubeDL(params=YTDL_FORMAT_OPTION) as ytdl:
        info = ytdl.extract_info(url="https://www.youtube.com/playlist?list=PLF_ZnpSKNQQFTeHaQ1ZR5l5cx5nRiD80w", download=False, process=False)
        
    print(len(list(info["entries"])))  # 86
    

if __name__ == "__main__":
    main()

len should display 5 instead of 86. Also, I checked that the option exist and can be passed in the params dict and we’re supposed to can (see here: https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L3207)

Maybe i’m doing something wrong or idk

Verbose log

[debug] Encodings: locale cp1252, fs utf-8, out cp1252 (No ANSI), err cp1252 (No ANSI), pref cp1252
[debug] yt-dlp version 2022.02.04 [c1653e9ef]
[debug] Compatibility options: n, o, -, y, o, u, t, u, b, e, -, u, n, a, v, a, i, l, a, b, l, e, -, v, i, d, e, o, s
[debug] Python version 3.9.9 (CPython 64bit) - Windows-10-10.0.19044-SP0
[debug] exe versions: ffmpeg 4.4-essentials_build-www.gyan.dev (setts), ffprobe 4.4-essentials_build-www.gyan.dev
[debug] Optional libraries: Cryptodome, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] [youtube:tab] Extracting URL: https://www.youtube.com/playlist?list=PLF_ZnpSKNQQFTeHaQ1ZR5l5cx5nRiD80w
[youtube:tab] PLF_ZnpSKNQQFTeHaQ1ZR5l5cx5nRiD80w: Downloading webpage
WARNING: [youtube:tab] YouTube said: INFO - 4 unavailable videos are hidden
[debug] [youtube:tab] Final URL: https://www.youtube.com/playlist?list=PLF_ZnpSKNQQFTeHaQ1ZR5l5cx5nRiD80w
WARNING: [youtube:tab] YouTube said: INFO - 4 unavailable videos are hidden

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Lesmiscorecommented, Feb 27, 2022

max_downloads is to limit number of downloads when you use download() function https://github.com/yt-dlp/yt-dlp/blob/03f830040ae92af369ee046b082b1683ddf1539f/yt_dlp/YoutubeDL.py#L3207-L3209

I see you want to limit number of items in playlists. To do this, either use 'playlistend': 5 (equivalent to --playlist-end 5) or 'playlist_items': '1-5' (--playlist-items 1-5)

P.S. You have to pass a list for compat_opts.

0reactions
Dystacommented, Feb 27, 2022

Yes, it’s what I need, thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

yt-dlp/yt-dlp: A youtube-dl fork with additional features ... - GitHub
If ffmpeg is used as the downloader, the downloading and merging of formats happen in a single step when possible. Use --compat-options no-direct-merge...
Read more >
yt-dlp(1) - Arch manual pages
Record the IDs of all downloaded videos in it; --no-download-archive: Do not use archive file (default); --max-downloads NUMBER: Abort after downloading NUMBER ...
Read more >
I can't embed thumbnails to the videos. : r/youtubedl - Reddit
Hello, recently I noticed that my downloaded videos no longer have the thumbnails embedded to them, I haven't changed any settings aside ...
Read more >
Tartube - The Easy Way To Watch And Download Videos
Tartube - The Easy Way To Watch And Download Videos. Works with YouTube, Twitch, Odysee, and hundreds of other sites. Tartube screenshot. 1...
Read more >
ytdl-org/youtube-dl - Buildpacks - Heroku Elements
youtube-dl is a command-line program to download videos from YouTube.com and a few more sites. It requires the Python interpreter, version 2.6, 2.7,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found