]> jfr.im git - yt-dlp.git/blame_incremental - devscripts/lazy_load_template.py
Add version to infojson
[yt-dlp.git] / devscripts / lazy_load_template.py
... / ...
CommitLineData
1import importlib
2import random
3import re
4
5from ..utils import (
6 age_restricted,
7 bug_reports_message,
8 classproperty,
9 write_string,
10)
11
12# These bloat the lazy_extractors, so allow them to passthrough silently
13ALLOWED_CLASSMETHODS = {'get_testcases', 'extract_from_webpage'}
14
15
16class LazyLoadMetaClass(type):
17 def __getattr__(cls, name):
18 if '_real_class' not in cls.__dict__ and name not in ALLOWED_CLASSMETHODS:
19 write_string(
20 'WARNING: Falling back to normal extractor since lazy extractor '
21 f'{cls.__name__} does not have attribute {name}{bug_reports_message()}\n')
22 return getattr(cls.real_class, name)
23
24
25class LazyLoadExtractor(metaclass=LazyLoadMetaClass):
26 @classproperty
27 def real_class(cls):
28 if '_real_class' not in cls.__dict__:
29 cls._real_class = getattr(importlib.import_module(cls._module), cls.__name__)
30 return cls._real_class
31
32 def __new__(cls, *args, **kwargs):
33 instance = cls.real_class.__new__(cls.real_class)
34 instance.__init__(*args, **kwargs)
35 return instance