Add experimental support for lazy loading the info extractors
[youtube-dl] / youtube_dl / extractor / __init__.py
1 from __future__ import unicode_literals
2
3 try:
4     from .lazy_extractors import *
5     from .lazy_extractors import _ALL_CLASSES
6 except ImportError:
7     from .extractors import *
8
9     _ALL_CLASSES = [
10         klass
11         for name, klass in globals().items()
12         if name.endswith('IE') and name != 'GenericIE'
13     ]
14     _ALL_CLASSES.append(GenericIE)
15
16
17 def gen_extractor_classes():
18     """ Return a list of supported extractors.
19     The order does matter; the first extractor matched is the one handling the URL.
20     """
21     return _ALL_CLASSES
22
23
24 def gen_extractors():
25     """ Return a list of an instance of every supported extractor.
26     The order does matter; the first extractor matched is the one handling the URL.
27     """
28     return [klass() for klass in gen_extractor_classes()]
29
30
31 def list_extractors(age_limit):
32     """
33     Return a list of extractors that are suitable for the given age,
34     sorted by extractor ID.
35     """
36
37     return sorted(
38         filter(lambda ie: ie.is_suitable(age_limit), gen_extractors()),
39         key=lambda ie: ie.IE_NAME.lower())
40
41
42 def get_info_extractor(ie_name):
43     """Returns the info extractor class with the given ie_name"""
44     return globals()[ie_name + 'IE']