diff --git a/test/test_plugins.py b/test/test_plugins.py index 8190b2ecd..28d1fa8fa 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -55,7 +55,7 @@ def reset_plugins(): plugin_ies.value = {} plugin_pps.value = {} - plugin_dirs.value = ['external'] + plugin_dirs.value = ['default'] plugin_specs.value = {} all_plugins_loaded.value = False plugins_enabled.value = True @@ -211,7 +211,7 @@ def test_set_plugin_dirs(self): set_plugin_dirs(custom_plugin_dir) self.assertEqual(plugin_dirs.value, [custom_plugin_dir]) - self.assertNotIn('external', plugin_dirs.value) + self.assertNotIn('default', plugin_dirs.value) load_plugins(EXTRACTOR_PLUGIN_SPEC) self.assertIn(f'{PACKAGE_NAME}.extractor.package', sys.modules.keys()) @@ -225,9 +225,9 @@ def test_invalid_plugin_dir(self): def test_add_plugin_dirs(self): custom_plugin_dir = str(TEST_DATA_DIR / 'plugin_packages') - self.assertEqual(plugin_dirs.value, ['external']) + self.assertEqual(plugin_dirs.value, ['default']) add_plugin_dirs(custom_plugin_dir) - self.assertEqual(plugin_dirs.value, ['external', custom_plugin_dir]) + self.assertEqual(plugin_dirs.value, ['default', custom_plugin_dir]) load_plugins(EXTRACTOR_PLUGIN_SPEC) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 6fa1051aa..76452ccac 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -40,7 +40,7 @@ plugin_overrides, plugin_pps, all_plugins_loaded, - plugins_enabled, + plugin_dirs, ) from .minicurses import format_text from .networking import HEADRequest, Request, RequestDirector @@ -4070,9 +4070,6 @@ def get_encoding(stream): write_debug(f'Proxy map: {self.proxies}') write_debug(f'Request Handlers: {", ".join(rh.RH_NAME for rh in self._request_director.handlers.values())}') - if os.environ.get('YTDLP_NO_PLUGINS'): - write_debug('Plugins are forcibly disabled') - return for plugin_type, plugins in (('Extractor', plugin_ies), ('Post-Processor', plugin_pps)): display_list = [ @@ -4085,12 +4082,12 @@ def get_encoding(stream): continue write_debug(f'{plugin_type} Plugins: {", ".join(sorted(display_list))}') - if not plugins_enabled.value: + if not plugin_dirs.value: write_debug('Plugins are disabled') - - plugin_dirs = plugin_directories() - if plugin_dirs and plugins_enabled.value: - write_debug(f'Plugin directories: {plugin_dirs}') + else: + loaded_plugin_directories = plugin_directories() + if loaded_plugin_directories: + write_debug(f'Plugin directories: {loaded_plugin_directories}') @functools.cached_property def proxies(self): diff --git a/yt_dlp/__init__.py b/yt_dlp/__init__.py index a88355b2b..3d466f3f6 100644 --- a/yt_dlp/__init__.py +++ b/yt_dlp/__init__.py @@ -430,11 +430,9 @@ def metadataparser_actions(f): } # Other options - opts.plugin_dirs = opts.plugin_dirs or [] - if 'no-external' not in opts.plugin_dirs: - opts.plugin_dirs.append('external') - else: - opts.plugin_dirs.remove('no-external') + opts.plugin_dirs = opts.plugin_dirs + if opts.plugin_dirs is None: + opts.plugin_dirs = ['default'] if opts.playlist_items is not None: try: @@ -993,11 +991,6 @@ def _real_main(argv=None): # load all plugins into the global lookup _set_plugin_dirs(*opts.plugin_dirs) - if not opts.plugins_enabled: - _disable_plugins() - else: - _load_all_plugins() - with YoutubeDL(ydl_opts) as ydl: pre_process = opts.update_self or opts.rm_cachedir actual_use = all_urls or opts.load_info_filename diff --git a/yt_dlp/_globals.py b/yt_dlp/_globals.py index 45e555b0f..b0f178ac2 100644 --- a/yt_dlp/_globals.py +++ b/yt_dlp/_globals.py @@ -21,8 +21,7 @@ def __repr__(self, /): # Plugins plugin_specs = Indirect({}) all_plugins_loaded = Indirect(False) -plugins_enabled = Indirect(True) -plugin_dirs = Indirect(['external']) +plugin_dirs = Indirect(['default']) plugin_ies = Indirect({}) plugin_overrides = Indirect(defaultdict(list)) plugin_pps = Indirect({}) diff --git a/yt_dlp/options.py b/yt_dlp/options.py index d0e71f58b..dc5ff9892 100644 --- a/yt_dlp/options.py +++ b/yt_dlp/options.py @@ -415,13 +415,12 @@ def _alias_callback(option, opt_str, value, parser, opts, nargs): action='append', help=( 'Path to an additional directory to search for plugins. ' - 'This option can be used multiple times to add multiple directories. ' - 'Add "no-external" to disable searching default external plugin directories (outside of python environment)')) + 'This option can be used multiple times to add multiple directories. ')) general.add_option( '--no-plugins', - dest='plugins_enabled', - action='store_false', - default=True, + dest='plugin_dirs', + action='store_const', + const=[], help='Do not load plugins') general.add_option( '--flat-playlist', diff --git a/yt_dlp/plugins.py b/yt_dlp/plugins.py index bea15afe0..cfabadd3d 100644 --- a/yt_dlp/plugins.py +++ b/yt_dlp/plugins.py @@ -19,7 +19,6 @@ plugin_dirs, all_plugins_loaded, plugin_specs, - plugins_enabled, Indirect, ) @@ -82,7 +81,7 @@ def dirs_in_zip(archive): return () -def external_plugin_paths(): +def default_plugin_paths(): def _get_package_paths(*root_paths, containing_folder): for config_dir in orderedSet(map(Path, root_paths), lazy=True): # We need to filter the base path added when running __main__.py directly @@ -141,7 +140,7 @@ def __init__(self, *packages): def search_locations(self, fullname): candidate_locations = itertools.chain.from_iterable( - external_plugin_paths() if candidate == 'external' else candidate_plugin_paths(candidate) + default_plugin_paths() if candidate == 'default' else candidate_plugin_paths(candidate) for candidate in plugin_dirs.value ) @@ -158,7 +157,7 @@ def search_locations(self, fullname): write_string(f'Permission error while accessing modules in "{e.filename}"\n') def find_spec(self, fullname, path=None, target=None): - if not plugins_enabled.value: + if not plugin_dirs.value: return None if fullname not in self.packages: @@ -206,7 +205,7 @@ def get_regular_classes(module, module_name, suffix): def load_plugins(plugin_spec: PluginSpec): name, suffix = plugin_spec.module_name, plugin_spec.suffix regular_classes = {} - if os.environ.get('YTDLP_NO_PLUGINS') or plugins_enabled.value is False: + if os.environ.get('YTDLP_NO_PLUGINS') or len(plugin_dirs.value) == 0: return regular_classes for finder, module_name, _ in iter_modules(name): @@ -233,7 +232,7 @@ def load_plugins(plugin_spec: PluginSpec): # Compat: old plugin system using __init__.py # Note: plugins imported this way do not show up in directories() # nor are considered part of the yt_dlp_plugins namespace package - if 'external' in plugin_dirs.value: + if 'default' in plugin_dirs.value: with contextlib.suppress(FileNotFoundError): spec = importlib.util.spec_from_file_location( name, @@ -287,4 +286,4 @@ def disable_plugins(): # note: we can't detect all cases when plugins are loaded (e.g. if spec isn't registered) raise YoutubeDLError('Plugins have already been loaded. Cannot disable plugins after loading plugins.') - plugins_enabled.value = False + plugin_dirs.value = []