]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/__init__.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / yt_dlp / extractor / __init__.py
1 from __future__ import unicode_literals
2
3 from ..utils import load_plugins
4
5 try:
6 from .lazy_extractors import *
7 from .lazy_extractors import _ALL_CLASSES
8 _LAZY_LOADER = True
9 _PLUGIN_CLASSES = []
10 except ImportError:
11 _LAZY_LOADER = False
12
13 if not _LAZY_LOADER:
14 from .extractors import *
15
16 _PLUGIN_CLASSES = load_plugins('extractor', 'IE', globals())
17
18 _ALL_CLASSES = [
19 klass
20 for name, klass in globals().items()
21 if name.endswith('IE') and name != 'GenericIE'
22 ]
23 _ALL_CLASSES.append(GenericIE)
24
25
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
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 """
37 return [klass() for klass in gen_extractor_classes()]
38
39
40 def 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
51 def get_info_extractor(ie_name):
52 """Returns the info extractor class with the given ie_name"""
53 return globals()[ie_name + 'IE']