Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of --no-config as an alias for --ignore-config #914

Closed
wants to merge 2 commits into from

Conversation

mezbaul-h
Copy link
Contributor

Before submitting a pull request make sure you have:

In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check one of the following options:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

  • Bug fix
  • Improvement
  • New extractor
  • New feature

Description of your pull request and other information

--no-config was introduced as an alias for --ignore-config but there were some cases where this was not reflected. This PR fixes those cases.

Fixes #912.

@pukkandan
Copy link
Member

Instead of hard-coding the switch names, I was thinking we should parse the options after each file is loaded. This will make it easier to expand the config file reading in future (eg: custom configs inside configs) and to add more "special" options (eg: #710 (comment))

Here's an initial draft:

--- a/yt_dlp/options.py
+++ b/yt_dlp/options.py
@@ -235,7 +235,7 @@ def parseOpts(overrideArguments=None):
         help='Use this prefix for unqualified URLs. For example "gvsearch2:" downloads two videos from google videos for the search term "large apple". Use the value "auto" to let yt-dlp guess ("auto_warning" to emit a warning when guessing). "error" just throws an error. The default value "fixup_error" repairs broken URLs, but emits an error if this is not possible instead of searching')
     general.add_option(
         '--ignore-config', '--no-config',
-        action='store_true',
+        action='store_true', dest='ignoreconfig',
         help=(
             'Disable loading any configuration files except the one provided by --config-location. '
             'When given inside a configuration file, no further configuration files are loaded. '
@@ -1533,26 +1533,26 @@ def parseOpts(overrideArguments=None):
             'command-line': compat_conf(sys.argv[1:]),
             'custom': [], 'home': [], 'portable': [], 'user': [], 'system': []}
         paths = {'command-line': False}
-        opts, args = parser.parse_args(configs['command-line'])

         def get_configs():
-            if '--config-location' in configs['command-line']:
+            opts, _ = parser.parse_args(configs['command-line'])
+            if opts.config_location is not None:
                 location = compat_expanduser(opts.config_location)
                 if os.path.isdir(location):
                     location = os.path.join(location, 'yt-dlp.conf')
                 if not os.path.exists(location):
                     parser.error('config-location %s does not exist.' % location)
-            if '--ignore-config' in configs['command-line']:
+            if opts.ignoreconfig:
                 return
-            if '--ignore-config' in configs['custom']:
+            if parser.parse_args(configs['custom'])[0].ignoreconfig:
                 return

-            def read_options(path, user=False):
+            def read_options(name, path, user=False):
+                ''' loads config files and returns ignoreconfig '''
                 # Multiple package names can be given here
                 # Eg: ('yt-dlp', 'youtube-dlc', 'youtube-dl') will look for
                 # the configuration file of any of these three packages
@@ -1563,27 +1563,18 @@ def parseOpts(overrideArguments=None):
                         current_path = os.path.join(path, '%s.conf' % package)
                         config = _readOptions(current_path, default=None)
                     if config is not None:
-                        return config, current_path
-                return [], None
+                        configs[name], paths[name] = config, current_path
+                        return parser.parse_args(config)[0].ignoreconfig
+                return False

-            configs['portable'], paths['portable'] = read_options(get_executable_path())
-            if '--ignore-config' in configs['portable']:
+            if read_options('portable', get_executable_path()):
                 return
-
-            def get_home_path():
-                opts = parser.parse_args(configs['portable'] + configs['custom'] + configs['command-line'])[0]
-                return expand_path(opts.paths.get('home', '')).strip()
-
-            configs['home'], paths['home'] = read_options(get_home_path())
-            if '--ignore-config' in configs['home']:
+            opts, _ = parser.parse_args(configs['portable'] + configs['custom'] + configs['command-line'])
+            if read_options('home', expand_path(opts.paths.get('home', '')).strip()):
                 return
-
-            configs['system'], paths['system'] = read_options('/etc')
-            if '--ignore-config' in configs['system']:
+            if read_options('system', '/etc'):
                 return
-
-            configs['user'], paths['user'] = read_options('', True)
-            if '--ignore-config' in configs['user']:
+            if read_options('user', None, user=True):
                 configs['system'], paths['system'] = [], None

         get_configs()

@pukkandan
Copy link
Member

Fixed by 7303f84

@pukkandan pukkandan closed this Sep 17, 2021
nixxo pushed a commit to nixxo/yt-dlp that referenced this pull request Nov 22, 2021
@mezbaul-h mezbaul-h deleted the fix-no-config branch March 10, 2022 08:16
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.

--no-config not honored, but --ignore-config behaves as expected
3 participants