]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/__init__.py
b35484246aadb75154ff4ed83216f2b207c67e32
[yt-dlp.git] / yt_dlp / extractor / __init__.py
1 import os
2
3 from ..utils import load_plugins
4
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
13
14 if not _LAZY_LOADER:
15 from .extractors import *
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)
22
23 _PLUGIN_CLASSES = load_plugins('extractor', 'IE', globals())
24 _ALL_CLASSES = list(_PLUGIN_CLASSES.values()) + _ALL_CLASSES
25
26
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
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 """
38 return [klass() for klass in gen_extractor_classes()]
39
40
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
52 def get_info_extractor(ie_name):
53 """Returns the info extractor class with the given ie_name"""
54 return globals()[ie_name + 'IE']