mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
set plugin_dirs to empty to disable plugins
This commit is contained in:
parent
fd236737b0
commit
0e825cd336
6 changed files with 24 additions and 37 deletions
|
@ -55,7 +55,7 @@
|
||||||
def reset_plugins():
|
def reset_plugins():
|
||||||
plugin_ies.value = {}
|
plugin_ies.value = {}
|
||||||
plugin_pps.value = {}
|
plugin_pps.value = {}
|
||||||
plugin_dirs.value = ['external']
|
plugin_dirs.value = ['default']
|
||||||
plugin_specs.value = {}
|
plugin_specs.value = {}
|
||||||
all_plugins_loaded.value = False
|
all_plugins_loaded.value = False
|
||||||
plugins_enabled.value = True
|
plugins_enabled.value = True
|
||||||
|
@ -211,7 +211,7 @@ def test_set_plugin_dirs(self):
|
||||||
set_plugin_dirs(custom_plugin_dir)
|
set_plugin_dirs(custom_plugin_dir)
|
||||||
|
|
||||||
self.assertEqual(plugin_dirs.value, [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)
|
load_plugins(EXTRACTOR_PLUGIN_SPEC)
|
||||||
|
|
||||||
self.assertIn(f'{PACKAGE_NAME}.extractor.package', sys.modules.keys())
|
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):
|
def test_add_plugin_dirs(self):
|
||||||
custom_plugin_dir = str(TEST_DATA_DIR / 'plugin_packages')
|
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)
|
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)
|
load_plugins(EXTRACTOR_PLUGIN_SPEC)
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
plugin_overrides,
|
plugin_overrides,
|
||||||
plugin_pps,
|
plugin_pps,
|
||||||
all_plugins_loaded,
|
all_plugins_loaded,
|
||||||
plugins_enabled,
|
plugin_dirs,
|
||||||
)
|
)
|
||||||
from .minicurses import format_text
|
from .minicurses import format_text
|
||||||
from .networking import HEADRequest, Request, RequestDirector
|
from .networking import HEADRequest, Request, RequestDirector
|
||||||
|
@ -4070,9 +4070,6 @@ def get_encoding(stream):
|
||||||
|
|
||||||
write_debug(f'Proxy map: {self.proxies}')
|
write_debug(f'Proxy map: {self.proxies}')
|
||||||
write_debug(f'Request Handlers: {", ".join(rh.RH_NAME for rh in self._request_director.handlers.values())}')
|
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)):
|
for plugin_type, plugins in (('Extractor', plugin_ies), ('Post-Processor', plugin_pps)):
|
||||||
display_list = [
|
display_list = [
|
||||||
|
@ -4085,12 +4082,12 @@ def get_encoding(stream):
|
||||||
continue
|
continue
|
||||||
write_debug(f'{plugin_type} Plugins: {", ".join(sorted(display_list))}')
|
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')
|
write_debug('Plugins are disabled')
|
||||||
|
else:
|
||||||
plugin_dirs = plugin_directories()
|
loaded_plugin_directories = plugin_directories()
|
||||||
if plugin_dirs and plugins_enabled.value:
|
if loaded_plugin_directories:
|
||||||
write_debug(f'Plugin directories: {plugin_dirs}')
|
write_debug(f'Plugin directories: {loaded_plugin_directories}')
|
||||||
|
|
||||||
@functools.cached_property
|
@functools.cached_property
|
||||||
def proxies(self):
|
def proxies(self):
|
||||||
|
|
|
@ -430,11 +430,9 @@ def metadataparser_actions(f):
|
||||||
}
|
}
|
||||||
|
|
||||||
# Other options
|
# Other options
|
||||||
opts.plugin_dirs = opts.plugin_dirs or []
|
opts.plugin_dirs = opts.plugin_dirs
|
||||||
if 'no-external' not in opts.plugin_dirs:
|
if opts.plugin_dirs is None:
|
||||||
opts.plugin_dirs.append('external')
|
opts.plugin_dirs = ['default']
|
||||||
else:
|
|
||||||
opts.plugin_dirs.remove('no-external')
|
|
||||||
|
|
||||||
if opts.playlist_items is not None:
|
if opts.playlist_items is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -993,11 +991,6 @@ def _real_main(argv=None):
|
||||||
# load all plugins into the global lookup
|
# load all plugins into the global lookup
|
||||||
_set_plugin_dirs(*opts.plugin_dirs)
|
_set_plugin_dirs(*opts.plugin_dirs)
|
||||||
|
|
||||||
if not opts.plugins_enabled:
|
|
||||||
_disable_plugins()
|
|
||||||
else:
|
|
||||||
_load_all_plugins()
|
|
||||||
|
|
||||||
with YoutubeDL(ydl_opts) as ydl:
|
with YoutubeDL(ydl_opts) as ydl:
|
||||||
pre_process = opts.update_self or opts.rm_cachedir
|
pre_process = opts.update_self or opts.rm_cachedir
|
||||||
actual_use = all_urls or opts.load_info_filename
|
actual_use = all_urls or opts.load_info_filename
|
||||||
|
|
|
@ -21,8 +21,7 @@ def __repr__(self, /):
|
||||||
# Plugins
|
# Plugins
|
||||||
plugin_specs = Indirect({})
|
plugin_specs = Indirect({})
|
||||||
all_plugins_loaded = Indirect(False)
|
all_plugins_loaded = Indirect(False)
|
||||||
plugins_enabled = Indirect(True)
|
plugin_dirs = Indirect(['default'])
|
||||||
plugin_dirs = Indirect(['external'])
|
|
||||||
plugin_ies = Indirect({})
|
plugin_ies = Indirect({})
|
||||||
plugin_overrides = Indirect(defaultdict(list))
|
plugin_overrides = Indirect(defaultdict(list))
|
||||||
plugin_pps = Indirect({})
|
plugin_pps = Indirect({})
|
||||||
|
|
|
@ -415,13 +415,12 @@ def _alias_callback(option, opt_str, value, parser, opts, nargs):
|
||||||
action='append',
|
action='append',
|
||||||
help=(
|
help=(
|
||||||
'Path to an additional directory to search for plugins. '
|
'Path to an additional directory to search for plugins. '
|
||||||
'This option can be used multiple times to add multiple directories. '
|
'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)'))
|
|
||||||
general.add_option(
|
general.add_option(
|
||||||
'--no-plugins',
|
'--no-plugins',
|
||||||
dest='plugins_enabled',
|
dest='plugin_dirs',
|
||||||
action='store_false',
|
action='store_const',
|
||||||
default=True,
|
const=[],
|
||||||
help='Do not load plugins')
|
help='Do not load plugins')
|
||||||
general.add_option(
|
general.add_option(
|
||||||
'--flat-playlist',
|
'--flat-playlist',
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
plugin_dirs,
|
plugin_dirs,
|
||||||
all_plugins_loaded,
|
all_plugins_loaded,
|
||||||
plugin_specs,
|
plugin_specs,
|
||||||
plugins_enabled,
|
|
||||||
Indirect,
|
Indirect,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -82,7 +81,7 @@ def dirs_in_zip(archive):
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
|
||||||
def external_plugin_paths():
|
def default_plugin_paths():
|
||||||
def _get_package_paths(*root_paths, containing_folder):
|
def _get_package_paths(*root_paths, containing_folder):
|
||||||
for config_dir in orderedSet(map(Path, root_paths), lazy=True):
|
for config_dir in orderedSet(map(Path, root_paths), lazy=True):
|
||||||
# We need to filter the base path added when running __main__.py directly
|
# 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):
|
def search_locations(self, fullname):
|
||||||
|
|
||||||
candidate_locations = itertools.chain.from_iterable(
|
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
|
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')
|
write_string(f'Permission error while accessing modules in "{e.filename}"\n')
|
||||||
|
|
||||||
def find_spec(self, fullname, path=None, target=None):
|
def find_spec(self, fullname, path=None, target=None):
|
||||||
if not plugins_enabled.value:
|
if not plugin_dirs.value:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if fullname not in self.packages:
|
if fullname not in self.packages:
|
||||||
|
@ -206,7 +205,7 @@ def get_regular_classes(module, module_name, suffix):
|
||||||
def load_plugins(plugin_spec: PluginSpec):
|
def load_plugins(plugin_spec: PluginSpec):
|
||||||
name, suffix = plugin_spec.module_name, plugin_spec.suffix
|
name, suffix = plugin_spec.module_name, plugin_spec.suffix
|
||||||
regular_classes = {}
|
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
|
return regular_classes
|
||||||
|
|
||||||
for finder, module_name, _ in iter_modules(name):
|
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
|
# Compat: old plugin system using __init__.py
|
||||||
# Note: plugins imported this way do not show up in directories()
|
# Note: plugins imported this way do not show up in directories()
|
||||||
# nor are considered part of the yt_dlp_plugins namespace package
|
# 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):
|
with contextlib.suppress(FileNotFoundError):
|
||||||
spec = importlib.util.spec_from_file_location(
|
spec = importlib.util.spec_from_file_location(
|
||||||
name,
|
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)
|
# 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.')
|
raise YoutubeDLError('Plugins have already been loaded. Cannot disable plugins after loading plugins.')
|
||||||
|
|
||||||
plugins_enabled.value = False
|
plugin_dirs.value = []
|
||||||
|
|
Loading…
Reference in a new issue