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.

[Embedding yt-dlp] Add options to redirect streams

See original GitHub issue

DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

  • I understand that I will be blocked if I remove or skip any mandatory* field

Checklist

  • I’m requesting a feature unrelated to a specific site
  • I’ve looked through the README
  • I’ve verified that I’m running yt-dlp version 2022.09.01 (update instructions) or later (specify commit)
  • I’ve searched the bugtracker for similar issues including closed ones. DO NOT post duplicates
  • I’ve read the guidelines for opening an issue

Provide a description that is worded well enough to be understood

I would like to use yt-dlp from within a Python script to get a list of the URLs of the videos in a playlist, preferably alongside the playlist’s metadata, without launching yt-dlp as a subprocess (i.e., via the Python interface). The command-line interface offers --flat-playlist --dump-single-json for this purpose, which maps to {"extract_flat": "in_playlist", "dump_single_json": True} in Python. However, this still prints the information to the command-line instead of a location where my Python script can access it.

In such situations, it would be useful to be able to pass in a stream object (e.g., an io.StringIO instance) to be written to instead of sys.stdout. Redirecting the log prints and error messages might also be useful for e.g. a Python GUI application that serves as a front-end to yt-dlp.

Implementing this seems easy (just document the options and modify the self._out_files = Namespace(...) assignment in YoutubeDL.py), but I wanted to post this first in case I am missing something. Also, do you think that out_stream, error_stream, screen_stream, and console_stream (after the names in the Namespace) are good names for the options?

Edit: I think dump_stream instead of out_stream and log_stream instead of screen_stream would be more telling, if I understood correctly what these streams are used for.

Off-topic:

While looking at the aforementioned assignment, I noticed that options that “dump to stdout,” like --dump-single-json, instead print to stderr if {"logtostderr": True} is passed. I find this confusing because these are not logging messages (you use {"quiet": True} to keep them out of stdout, although logtostderr will also affect those). Is this name kept for compatibility reasons? At least the documentation should be updated – it currently reads:

    logtostderr:       Log messages to stderr instead of stdout.

Also, where is “--dump-single-json implies --quiet” implemented?

Provide verbose output that clearly demonstrates the problem

  • Run your yt-dlp command with -vU flag added (yt-dlp -vU <your command line>)
  • Copy the WHOLE output (starting with [debug] Command-line config) and insert it below

Complete Verbose Output

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pukkandancommented, Sep 7, 2022

I think I dismissed extract_info() because I was misled by its docstring, which reads like playlist metadata will never be returned:

        Return a list with a dictionary for each video extracted.

Damn, it looks like the docstring wasn’t updated in years!

As another example, a command-line application written in Python that uses yt-dlp in the background might not want to print logging and error messages to the command line but instead write them to a log file.

https://github.com/yt-dlp/yt-dlp#adding-logger-and-progress-hook

Also, where is “–dump-single-json implies --quiet” implemented?

This only applies to CLI

I was just asking this to get a better understanding of the code.

https://github.com/yt-dlp/yt-dlp/blob/7657ec7ed6318dd66dd72cc100ba7bc5b911366e/yt_dlp/__init__.py#L741

0reactions
pukkandancommented, Sep 7, 2022

The documentation mistakes have been fixed

Read more comments on GitHub >

github_iconTop Results From Across the Web

yt-dlp(1) - Arch manual pages
Extract the videos of a playlist; --live-from-start: Download livestreams from the start. Currently only supported for YouTube (Experimental); --no-live-from- ...
Read more >
YTDLP Different options for different websites ? : r/youtubedl
Can I set YTDLP such that it uses a different set of options for different ... to another site (Eg: a reddit post...
Read more >
Yt dlp A YouTube dl fork with additional features and fixes
You may use --compat-options no-youtube-channel-redirect to revert all these redirections . Append a to the URL to download only the videos in the...
Read more >
Is it possible to not change the file created date when ...
But if I was also embedding the thumbnail to the output using --add-metadata --embed-thumbnail {URL} , the "Date created" and "Date ...
Read more >
yt-dlp 2022.11.11 Free Download - VideoHelp
[outtmpl] Ensure ASCII in json and add option for Unicode [SponsorBlock] Add type field, ... [extractor/generic] Separate embed extraction into own function
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