Skip to content

feat: apply yt-dlp config files to downloads - #428

Open
manbearwiz wants to merge 1 commit into
mainfrom
feat/ydl-config-files
Open

manbearwiz wants to merge 1 commit into
mainfrom
feat/ydl-config-files

Conversation

@manbearwiz

Copy link
Copy Markdown
Owner

Refs #24, #29, #298. An alternative to #427.

Why

The README tells you to mount a yt-dlp config directory at /root/.config/yt-dlp, and the 32-bit ARM images write --js-runtimes node to /etc/yt-dlp/config. Neither has ever had any effect. Only yt-dlp's command line reads config files; the YoutubeDL embedding API never does. Config support was lost when the server moved from shelling out to the CLI to the Python API in 98bc4fa (Dec 2018); #24 was filed 17 days later. The docs and the ARM config came later, in #329, assuming CLI behavior.

How

Instead of merging a config file's params into the server's by hand, the server builds each download the way the yt-dlp command line does. It makes one argument list, lowest precedence first:

  1. the server's defaults (.env.example)
  2. the config files: yt-dlp's system and user lookup, read with yt-dlp's own Config.read_file
  3. the YDL_* options the environment or .env sets
  4. the request's format

and passes it to yt-dlp's public parse_options. yt-dlp then does all the merging: postprocessor order, extra output templates (pl_thumbnail), metadata and chapter options. There is no merging code in the server. Each YDL_* option is now one row mapping it to its CLI flag (YDL_ARGS).

The one rule yt-dlp can't express: a request format that names a codec or container replaces the conversion from every other source (the existing one-pipeline rule from #403). -x has no negation, so the other converters are filtered out afterwards and final_ext is the request's.

Robustness

  • Each YDL_* value yt-dlp takes, and each config file, is checked by yt-dlp at startup. A bad one is logged as a warning and ignored, like an unparseable option today, so it can't fail every download.
  • Config and the config-dir helpers aren't in yt-dlp's __all__. If an upgrade moves them, the server logs a warning and runs without config files instead of failing to start.
  • The log names the config files used, never their contents, since a config file can hold credentials.
  • /healthz checks the output template downloads actually use, so a config file's -o counts.

Behavior changes

  • Installs that mount a config file now get it applied, as the README promised. On arm/v7 and arm/v6, /etc/yt-dlp/config now takes effect, so yt-dlp uses the node runtime the image installs.
  • Downloads start from yt-dlp's command-line defaults rather than its API defaults. Notable ones: the playlist-stage FFmpegConcat for multi-part videos is present, and YDL_EMBED_METADATA maps to --embed-metadata, which also embeds chapters.
  • yt-dlp's own option warnings (e.g. for -f best) now appear in the log.

Tests

The existing option tests are kept and now compare the postprocessors that run on each file, which leaves out the playlist-stage FFmpegConcat. New tests cover: system-then-user lookup, no config file, an unparseable config file, a config file replacing defaults, a set YDL_* winning over a config file, /healthz following a config -o, pass-through options, a request format replacing a config conversion (with yt-dlp's ordering and final_ext), and a bad YDL_* value warning. ruff check, ruff format --check and pytest (53) pass. I also imported the module with a real config file (--embed-thumbnail, --sponsorblock-remove, -o) and built YoutubeDL from the options for no format, mp3 and mp4. The config's output path, SponsorBlock and EmbedThumbnail applied, and the request's converter ran first in each case. No real download was run.

🤖 Generated with Claude Code

The README documents mounting a yt-dlp config directory at
/root/.config/yt-dlp, and the 32-bit ARM images write --js-runtimes node to
/etc/yt-dlp/config. Neither has had any effect since the server moved from
the youtube-dl command line to the embedding API (98bc4fa, 2018): only
yt-dlp's command line reads config files.

The server now reads them at startup with yt-dlp's own reader, from its
system and user lookup, and builds each download's params the way the
yt-dlp command line does: one argument list, lowest precedence first --
the server's defaults, the config files, the YDL_* options that are set,
then the request's format -- passed to yt-dlp's public parse_options. yt-dlp
itself then merges them, so postprocessor order, output templates and
metadata options follow its rules with no merging code here. The one
exception is a request format, which replaces the conversion from every
other source: -x has no negation, so the other converters are dropped and
final_ext is the request's.

Each YDL_* value yt-dlp takes, and each config file, is checked by yt-dlp
at startup; a bad one warns and is ignored, as an unparseable option already
is. The log names the config files used, never their contents. /healthz
checks the output template downloads actually use.

Downloads now start from yt-dlp's command-line defaults rather than its API
defaults, e.g. the playlist-stage FFmpegConcat for multi-part videos and
--embed-metadata also embedding chapters.

Refs #24, #29, #298

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant