]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/__init__.py
[postprocessor] Add plugin support
[yt-dlp.git] / yt_dlp / extractor / __init__.py
CommitLineData
dcddc10a
PH
1from __future__ import unicode_literals
2
f74980cb 3from ..utils import load_plugins
4
779822d9
JMF
5try:
6 from .lazy_extractors import *
7 from .lazy_extractors import _ALL_CLASSES
e0986e31 8 _LAZY_LOADER = True
3ae5e797 9 _PLUGIN_CLASSES = {}
779822d9 10except ImportError:
e0986e31 11 _LAZY_LOADER = False
0748b331 12
13if not _LAZY_LOADER:
779822d9 14 from .extractors import *
779822d9
JMF
15 _ALL_CLASSES = [
16 klass
17 for name, klass in globals().items()
18 if name.endswith('IE') and name != 'GenericIE'
19 ]
20 _ALL_CLASSES.append(GenericIE)
f9c6cbf0 21
2f567473 22 _PLUGIN_CLASSES = load_plugins('extractor', 'IE', globals())
3ae5e797 23 _ALL_CLASSES = list(_PLUGIN_CLASSES.values()) + _ALL_CLASSES
2f567473 24
9460db83 25
e52d7f85
JMF
26def 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
33def 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
05900629
PH
40def list_extractors(age_limit):
41 """
42 Return a list of extractors that are suitable for the given age,
43 sorted by extractor ID.
44 """
45
46 return sorted(
47 filter(lambda ie: ie.is_suitable(age_limit), gen_extractors()),
48 key=lambda ie: ie.IE_NAME.lower())
49
50
f9c6cbf0
PH
51def get_info_extractor(ie_name):
52 """Returns the info extractor class with the given ie_name"""
8bcc8756 53 return globals()[ie_name + 'IE']