From 61f3860ed6be828b5ffe76952df8394f076bc019 Mon Sep 17 00:00:00 2001 From: Jessica Hamilton Date: Thu, 28 Nov 2024 18:26:00 +1300 Subject: [PATCH] Fix passing arguments to yt-dlp. As mentioned in https://github.com/yt-dlp/yt-dlp/issues/10196, `yt_dlp.parse_options` should be used for parsing command line flags. However, as this API doesn't take in a set of configured options, the defaults handling is a little bit messier. Basically checks for any non-default values after parsing the command line flags, and skips setting them from the `defaults` dictionary. This fixes #2242. --- spotdl/utils/formatter.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/spotdl/utils/formatter.py b/spotdl/utils/formatter.py index 14e54eb63..fdba39249 100644 --- a/spotdl/utils/formatter.py +++ b/spotdl/utils/formatter.py @@ -15,8 +15,7 @@ import pykakasi from rapidfuzz import fuzz from slugify import slugify as py_slugify -from yt_dlp.options import create_parser -from yt_dlp.options import optparse as yt_dlp_optparse +from yt_dlp import parse_options from yt_dlp.utils import sanitize_filename from spotdl.types.song import Song @@ -70,7 +69,6 @@ ) DISALLOWED_REGEX = re.compile(r"[^-a-zA-Z0-9\!\@\$]+") -YT_DLP_PARSER = create_parser() logger = logging.getLogger(__name__) @@ -622,6 +620,17 @@ def args_to_ytdlp_options( - the dictionary of options """ - new_args = YT_DLP_PARSER.parse_args(argument_list, yt_dlp_optparse.Values(defaults)) + parsed_options = parse_options(argument_list).ydl_opts - return vars(new_args[0]) + if defaults is None: + return parsed_options + + default_options = parse_options([]).ydl_opts + + for key, value in defaults.items(): + if key not in parsed_options: + parsed_options[key] = value + elif parsed_options[key] == default_options[key]: + parsed_options[key] = value + + return parsed_options