]> jfr.im git - yt-dlp.git/blame - devscripts/lazy_load_template.py
[Hotstar] Bugfix for a1ddaa899ca8693f31f34770f7263ace7e8c8841
[yt-dlp.git] / devscripts / lazy_load_template.py
CommitLineData
82d02080 1import importlib
2import random
779822d9
JMF
3import re
4
82d02080 5from ..utils import bug_reports_message, classproperty, write_string
e6f21b3d 6
779822d9 7
5bc4a65e 8class LazyLoadMetaClass(type):
9 def __getattr__(cls, name):
82d02080 10 # "is_suitable" requires "_TESTS". However, they bloat the lazy_extractors
11 if '_real_class' not in cls.__dict__ and name not in ('is_suitable', 'get_testcases'):
e6f21b3d 12 write_string(
1d485a1a 13 'WARNING: Falling back to normal extractor since lazy extractor '
82d02080 14 f'{cls.__name__} does not have attribute {name}{bug_reports_message()}\n')
15 return getattr(cls.real_class, name)
5bc4a65e 16
17
18class LazyLoadExtractor(metaclass=LazyLoadMetaClass):
82d02080 19 @classproperty
20 def real_class(cls):
e6f21b3d 21 if '_real_class' not in cls.__dict__:
82d02080 22 cls._real_class = getattr(importlib.import_module(cls._module), cls.__name__)
e6f21b3d 23 return cls._real_class
5bc4a65e 24
8a5dc1c1 25 def __new__(cls, *args, **kwargs):
82d02080 26 instance = cls.real_class.__new__(cls.real_class)
8a5dc1c1
JMF
27 instance.__init__(*args, **kwargs)
28 return instance