]>
jfr.im git - yt-dlp.git/blob - devscripts/make_lazy_extractors.py
5d0ddb40180715c5e2d5db17075190e7909708d1
1 from __future__
import unicode_literals
, print_function
3 from inspect
import getsource
5 from os
.path
import dirname
as dirn
8 print('WARNING: Lazy loading extractors is an experimental feature that may not always work', file=sys
.stderr
)
10 sys
.path
.insert(0, dirn(dirn((os
.path
.abspath(__file__
)))))
12 lazy_extractors_filename
= sys
.argv
[1]
13 if os
.path
.exists(lazy_extractors_filename
):
14 os
.remove(lazy_extractors_filename
)
16 from youtube_dl
.extractor
import _ALL_CLASSES
17 from youtube_dl
.extractor
.common
import InfoExtractor
19 with open('devscripts/lazy_load_template.py', 'rt') as f
:
20 module_template
= f
.read()
22 module_contents
= [module_template
+ '\n' + getsource(InfoExtractor
.suitable
)]
25 class {name}(LazyLoadExtractor):
26 _VALID_URL = {valid_url!r}
30 make_valid_template
= '''
32 def _make_valid_url(cls):
37 def build_lazy_ie(ie
, name
):
38 valid_url
= getattr(ie
, '_VALID_URL', None)
39 s
= ie_template
.format(
43 if ie
.suitable
.__func
__ is not InfoExtractor
.suitable
.__func
__:
44 s
+= getsource(ie
.suitable
)
45 if hasattr(ie
, '_make_valid_url'):
47 s
+= make_valid_template
.format(valid_url
=ie
._make
_valid
_url
())
51 for ie
in _ALL_CLASSES
:
52 name
= ie
.ie_key() + 'IE'
53 src
= build_lazy_ie(ie
, name
)
54 module_contents
.append(src
)
57 module_contents
.append(
58 '_ALL_CLASSES = [{0}]'.format(', '.join(names
)))
60 module_src
= '\n'.join(module_contents
)
62 with open(lazy_extractors_filename
, 'wt') as f
: