diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-06-15 18:00:34 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-06-16 06:23:50 +0530 |
commit | 560738f34de4df6eaf82290fd503def3f366f878 (patch) | |
tree | abaf12930736e70b39a3a1b45500408ca020cf2c /yt_dlp/extractor/extractors.py | |
parent | 99d10bf60796a90d2ca421ec63f1208b15ae5f48 (diff) | |
download | hypervideo-pre-560738f34de4df6eaf82290fd503def3f366f878.tar.lz hypervideo-pre-560738f34de4df6eaf82290fd503def3f366f878.tar.xz hypervideo-pre-560738f34de4df6eaf82290fd503def3f366f878.zip |
[extractor] Import `_ALL_CLASSES` lazily
This significantly speeds up `import yt_dlp` in the absence of `lazy_extractors`
Diffstat (limited to 'yt_dlp/extractor/extractors.py')
-rw-r--r-- | yt_dlp/extractor/extractors.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py new file mode 100644 index 000000000..32818a024 --- /dev/null +++ b/yt_dlp/extractor/extractors.py @@ -0,0 +1,23 @@ +import contextlib +import os + +from ..utils import load_plugins + +_LAZY_LOADER = False +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 + +if not _LAZY_LOADER: + from ._extractors import * # noqa: F403 + _ALL_CLASSES = [ # noqa: F811 + klass + for name, klass in globals().items() + if name.endswith('IE') and name != 'GenericIE' + ] + _ALL_CLASSES.append(GenericIE) # noqa: F405 + +_PLUGIN_CLASSES = load_plugins('extractor', 'IE', globals()) +_ALL_CLASSES = list(_PLUGIN_CLASSES.values()) + _ALL_CLASSES |