Skip to content

Commit d81c601

Browse files
authored
Fix passing arguments to yt-dlp. (#2250)
As mentioned in yt-dlp/yt-dlp#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. # Title <!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> ## Related Issue <!--- This project only accepts pull requests related to open issues --> <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Please link to the issue here: --> ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Screenshots (if appropriate) ## Types of Changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] My code follows the code style of this project - [ ] My change requires a change to the documentation - [ ] I have updated the documentation accordingly - [ ] I have read the [CONTRIBUTING](/docs/CONTRIBUTING.md) document - [ ] I have read the [CORE VALUES](/docs/CORE_VALUES.md) document - [ ] I have added tests to cover my changes - [ ] All new and existing tests passed
2 parents 8273124 + b8f4e4e commit d81c601

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

spotdl/utils/formatter.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
import pykakasi
1616
from rapidfuzz import fuzz
1717
from slugify import slugify as py_slugify
18-
from yt_dlp.options import create_parser
19-
from yt_dlp.options import optparse as yt_dlp_optparse
18+
from yt_dlp import parse_options
2019
from yt_dlp.utils import sanitize_filename
2120

2221
from spotdl.types.song import Song
@@ -70,7 +69,6 @@
7069
)
7170

7271
DISALLOWED_REGEX = re.compile(r"[^-a-zA-Z0-9\!\@\$]+")
73-
YT_DLP_PARSER = create_parser()
7472

7573
logger = logging.getLogger(__name__)
7674

@@ -622,6 +620,17 @@ def args_to_ytdlp_options(
622620
- the dictionary of options
623621
"""
624622

625-
new_args = YT_DLP_PARSER.parse_args(argument_list, yt_dlp_optparse.Values(defaults))
623+
parsed_options = parse_options(argument_list).ydl_opts
626624

627-
return vars(new_args[0])
625+
if defaults is None:
626+
return parsed_options
627+
628+
default_options = parse_options([]).ydl_opts
629+
630+
for key, value in defaults.items():
631+
if key not in parsed_options:
632+
parsed_options[key] = value
633+
elif parsed_options[key] == default_options[key]:
634+
parsed_options[key] = value
635+
636+
return parsed_options

0 commit comments

Comments
 (0)