[Embedding yt-dlp] Add options to redirect streams
See original GitHub issueDO 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:
- Created a year ago
- Comments:5 (4 by maintainers)
Damn, it looks like the docstring wasn’t updated in years!
https://github.com/yt-dlp/yt-dlp#adding-logger-and-progress-hook
https://github.com/yt-dlp/yt-dlp/blob/7657ec7ed6318dd66dd72cc100ba7bc5b911366e/yt_dlp/__init__.py#L741
The documentation mistakes have been fixed