mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-31 06:35:12 +00:00 
			
		
		
		
	[core] Load plugins on demand (#11305)
- Adds `--no-plugin-dirs` to disable plugin loading - `--plugin-dirs` now supports post-processors Authored by: coletdjnz, Grub4K, pukkandan
This commit is contained in:
		| @@ -1,28 +1,35 @@ | ||||
| import contextlib | ||||
| import inspect | ||||
| import os | ||||
| 
 | ||||
| from ..plugins import load_plugins | ||||
| from ..globals import LAZY_EXTRACTORS | ||||
| from ..globals import extractors as _extractors_context | ||||
| 
 | ||||
| # NB: Must be before other imports so that plugins can be correctly injected | ||||
| _PLUGIN_CLASSES = load_plugins('extractor', 'IE') | ||||
| 
 | ||||
| _LAZY_LOADER = False | ||||
| _CLASS_LOOKUP = None | ||||
| if not os.environ.get('YTDLP_NO_LAZY_EXTRACTORS'): | ||||
|     with contextlib.suppress(ImportError): | ||||
|         from .lazy_extractors import *  # noqa: F403 | ||||
|         from .lazy_extractors import _ALL_CLASSES | ||||
|         _LAZY_LOADER = True | ||||
|     try: | ||||
|         from .lazy_extractors import _CLASS_LOOKUP | ||||
|         LAZY_EXTRACTORS.value = True | ||||
|     except ImportError: | ||||
|         LAZY_EXTRACTORS.value = False | ||||
| 
 | ||||
| if not _LAZY_LOADER: | ||||
|     from ._extractors import *  # noqa: F403 | ||||
|     _ALL_CLASSES = [  # noqa: F811 | ||||
|         klass | ||||
|         for name, klass in globals().items() | ||||
| if not _CLASS_LOOKUP: | ||||
|     from . import _extractors | ||||
| 
 | ||||
|     _CLASS_LOOKUP = { | ||||
|         name: value | ||||
|         for name, value in inspect.getmembers(_extractors) | ||||
|         if name.endswith('IE') and name != 'GenericIE' | ||||
|     ] | ||||
|     _ALL_CLASSES.append(GenericIE)  # noqa: F405 | ||||
|     } | ||||
|     _CLASS_LOOKUP['GenericIE'] = _extractors.GenericIE | ||||
| 
 | ||||
| globals().update(_PLUGIN_CLASSES) | ||||
| _ALL_CLASSES[:0] = _PLUGIN_CLASSES.values() | ||||
| # We want to append to the main lookup | ||||
| _current = _extractors_context.value | ||||
| for name, ie in _CLASS_LOOKUP.items(): | ||||
|     _current.setdefault(name, ie) | ||||
| 
 | ||||
| from .common import _PLUGIN_OVERRIDES  # noqa: F401 | ||||
| 
 | ||||
| def __getattr__(name): | ||||
|     value = _CLASS_LOOKUP.get(name) | ||||
|     if not value: | ||||
|         raise AttributeError(f'module {__name__} has no attribute {name}') | ||||
|     return value | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 coletdjnz
					coletdjnz