Created
August 10, 2025 13:22
-
-
Save arabcoders/27ad24a9962bc98d85de591c914fb295 to your computer and use it in GitHub Desktop.
Convert yt-dlp command line arguments to dict for easier handling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def arg_converter(cli_args: str) -> dict: | |
| """ | |
| Convert yt-dlp options to a dict. | |
| Args: | |
| cli_args (str): yt-dlp options string. | |
| Returns: | |
| dict: yt-dlp options dictionary. | |
| """ | |
| import shlex | |
| import yt_dlp.options | |
| create_parser = yt_dlp.options.create_parser | |
| def _default_opts(args: str): | |
| patched_parser = create_parser() | |
| try: | |
| yt_dlp.options.create_parser = lambda: patched_parser | |
| return yt_dlp.parse_options(args) | |
| finally: | |
| yt_dlp.options.create_parser = create_parser | |
| default_opts = _default_opts([]).ydl_opts | |
| opts = yt_dlp.parse_options(shlex.split(cli_args)).ydl_opts | |
| diff = {k: v for k, v in opts.items() if default_opts[k] != v} | |
| if "postprocessors" in diff: | |
| diff["postprocessors"] = [pp for pp in diff["postprocessors"] if pp not in default_opts["postprocessors"]] | |
| if "_warnings" in diff: | |
| diff.pop("_warnings", None) | |
| return diff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment