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