]>
Commit | Line | Data |
---|---|---|
19a03940 | 1 | import contextlib |
6e21fdd2 | 2 | import os |
dcddc10a | 3 | |
f74980cb | 4 | from ..utils import load_plugins |
5 | ||
6e21fdd2 | 6 | _LAZY_LOADER = False |
7 | if not os.environ.get('YTDLP_NO_LAZY_EXTRACTORS'): | |
19a03940 | 8 | with contextlib.suppress(ImportError): |
9 | from .lazy_extractors import * # noqa: F403 | |
6e21fdd2 | 10 | from .lazy_extractors import _ALL_CLASSES |
11 | _LAZY_LOADER = True | |
0748b331 | 12 | |
13 | if not _LAZY_LOADER: | |
19a03940 | 14 | from .extractors import * # noqa: F403 |
15 | _ALL_CLASSES = [ # noqa: F811 | |
779822d9 JMF |
16 | klass |
17 | for name, klass in globals().items() | |
18 | if name.endswith('IE') and name != 'GenericIE' | |
19 | ] | |
19a03940 | 20 | _ALL_CLASSES.append(GenericIE) # noqa: F405 |
f9c6cbf0 | 21 | |
6e21fdd2 | 22 | _PLUGIN_CLASSES = load_plugins('extractor', 'IE', globals()) |
23 | _ALL_CLASSES = list(_PLUGIN_CLASSES.values()) + _ALL_CLASSES | |
2f567473 | 24 | |
9460db83 | 25 | |
e52d7f85 JMF |
26 | def gen_extractor_classes(): |
27 | """ Return a list of supported extractors. | |
28 | The order does matter; the first extractor matched is the one handling the URL. | |
29 | """ | |
30 | return _ALL_CLASSES | |
31 | ||
32 | ||
f9c6cbf0 PH |
33 | def gen_extractors(): |
34 | """ Return a list of an instance of every supported extractor. | |
35 | The order does matter; the first extractor matched is the one handling the URL. | |
36 | """ | |
e52d7f85 | 37 | return [klass() for klass in gen_extractor_classes()] |
f9c6cbf0 | 38 | |
9460db83 | 39 | |
82d02080 | 40 | def list_extractor_classes(age_limit=None): |
8dcce6a8 | 41 | """Return a list of extractors that are suitable for the given age, sorted by extractor name""" |
82d02080 | 42 | yield from sorted(filter( |
43 | lambda ie: ie.is_suitable(age_limit) and ie != GenericIE, # noqa: F405 | |
44 | gen_extractor_classes()), key=lambda ie: ie.IE_NAME.lower()) | |
45 | yield GenericIE # noqa: F405 | |
46 | ||
47 | ||
48 | def list_extractors(age_limit=None): | |
49 | """Return a list of extractor instances that are suitable for the given age, sorted by extractor name""" | |
50 | return [ie() for ie in list_extractor_classes(age_limit)] | |
05900629 PH |
51 | |
52 | ||
f9c6cbf0 PH |
53 | def get_info_extractor(ie_name): |
54 | """Returns the info extractor class with the given ie_name""" | |
8bcc8756 | 55 | return globals()[ie_name + 'IE'] |