A feature-rich command-line audio/video downloader
Fix lazy extractor bug in fe7866d0ed6bfa3904ce12b049a3424fdc0ea1fa
pukkandane5458d1d88fc
diff --git a/devscripts/lazy_load_template.py b/devscripts/lazy_load_template.pyindex a6e26b6f63..626b85d620 100644--- a/devscripts/lazy_load_template.py+++ b/devscripts/lazy_load_template.py@@ -11,14 +11,17 @@ from ..utils import (# These bloat the lazy_extractors, so allow them to passthrough silentlyALLOWED_CLASSMETHODS = {'get_testcases', 'extract_from_webpage'}+_WARNED = Falseclass LazyLoadMetaClass(type):def __getattr__(cls, name):- if '_real_class' not in cls.__dict__ and name not in ALLOWED_CLASSMETHODS:- write_string(- 'WARNING: Falling back to normal extractor since lazy extractor '- f'{cls.__name__} does not have attribute {name}{bug_reports_message()}\n')+ global _WARNED+ if ('_real_class' not in cls.__dict__+ and name not in ALLOWED_CLASSMETHODS and not _WARNED):+ _WARNED = True+ write_string('WARNING: Falling back to normal extractor since lazy extractor '+ f'{cls.__name__} does not have attribute {name}{bug_reports_message()}\n')return getattr(cls.real_class, name)diff --git a/devscripts/make_lazy_extractors.py b/devscripts/make_lazy_extractors.pyindex 01bd88ae61..43885331f8 100644--- a/devscripts/make_lazy_extractors.py+++ b/devscripts/make_lazy_extractors.py@@ -12,7 +12,9 @@ from inspect import getsourcefrom devscripts.utils import get_filename_args, read_file, write_fileNO_ATTR = object()-STATIC_CLASS_PROPERTIES = ['IE_NAME', 'IE_DESC', 'SEARCH_KEY', '_VALID_URL', '_WORKING', '_NETRC_MACHINE', 'age_limit']+STATIC_CLASS_PROPERTIES = [+ 'IE_NAME', 'IE_DESC', 'SEARCH_KEY', '_VALID_URL', '_WORKING', '_ENABLED', '_NETRC_MACHINE', 'age_limit'+]CLASS_METHODS = ['ie_key', 'working', 'description', 'suitable', '_match_valid_url', '_match_id', 'get_temp_id', 'is_suitable']diff --git a/test/test_execution.py b/test/test_execution.pyindex 1d15fddabc..7a9e800b66 100644--- a/test/test_execution.py+++ b/test/test_execution.py@@ -11,41 +11,46 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import contextlibimport subprocess-from yt_dlp.utils import encodeArgument+from yt_dlp.utils import PopenrootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+LAZY_EXTRACTORS = 'yt_dlp/extractor/lazy_extractors.py'-try:- _DEV_NULL = subprocess.DEVNULL-except AttributeError:- _DEV_NULL = open(os.devnull, 'wb')+class TestExecution(unittest.TestCase):+ def run_yt_dlp(self, exe=(sys.executable, 'yt_dlp/__main__.py'), opts=('--version', )):+ stdout, stderr, returncode = Popen.run(+ [*exe, '--ignore-config', *opts], cwd=rootDir, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)+ print(stderr, file=sys.stderr)+ self.assertEqual(returncode, 0)+ return stdout.strip(), stderr.strip()+ def test_main_exec(self):+ self.run_yt_dlp()-class TestExecution(unittest.TestCase):def test_import(self):- subprocess.check_call([sys.executable, '-c', 'import yt_dlp'], cwd=rootDir)+ self.run_yt_dlp(exe=(sys.executable, '-c', 'import yt_dlp'))def test_module_exec(self):- subprocess.check_call([sys.executable, '-m', 'yt_dlp', '--ignore-config', '--version'], cwd=rootDir, stdout=_DEV_NULL)-- def test_main_exec(self):- subprocess.check_call([sys.executable, 'yt_dlp/__main__.py', '--ignore-config', '--version'], cwd=rootDir, stdout=_DEV_NULL)+ self.run_yt_dlp(exe=(sys.executable, '-m', 'yt_dlp'))def test_cmdline_umlauts(self):- p = subprocess.Popen(- [sys.executable, 'yt_dlp/__main__.py', '--ignore-config', encodeArgument('ä'), '--version'],- cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE)- _, stderr = p.communicate()+ _, stderr = self.run_yt_dlp(opts=('ä', '--version'))self.assertFalse(stderr)def test_lazy_extractors(self):try:- subprocess.check_call([sys.executable, 'devscripts/make_lazy_extractors.py', 'yt_dlp/extractor/lazy_extractors.py'], cwd=rootDir, stdout=_DEV_NULL)- subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=_DEV_NULL)+ subprocess.check_call([sys.executable, 'devscripts/make_lazy_extractors.py', LAZY_EXTRACTORS],+ cwd=rootDir, stdout=subprocess.DEVNULL)+ self.assertTrue(os.path.exists(LAZY_EXTRACTORS))++ _, stderr = self.run_yt_dlp(opts=('-s', 'test:'))+ self.assertFalse(stderr)++ subprocess.check_call([sys.executable, 'test/test_all_urls.py'], cwd=rootDir, stdout=subprocess.DEVNULL)finally:with contextlib.suppress(OSError):- os.remove('yt_dlp/extractor/lazy_extractors.py')+ os.remove(LAZY_EXTRACTORS)if __name__ == '__main__':diff --git a/yt_dlp/extractor/testurl.py b/yt_dlp/extractor/testurl.pyindex d205fe053f..2bce3b239a 100644--- a/yt_dlp/extractor/testurl.py+++ b/yt_dlp/extractor/testurl.py@@ -8,12 +8,14 @@ class TestURLIE(InfoExtractor):""" Allows addressing of the test cases as test:yout.*be_1 """IE_DESC = False # Do not list- _VALID_URL = r'test(?:url)?:(?P<extractor>.+?)(?:_(?P<num>[0-9]+))?$'+ _VALID_URL = r'test(?:url)?:(?P<extractor>.*?)(?:_(?P<num>[0-9]+))?$'def _real_extract(self, url):from . import gen_extractor_classesextractor_id, num = self._match_valid_url(url).group('extractor', 'num')+ if not extractor_id:+ return {'id': ':test', 'title': '', 'url': url}rex = re.compile(extractor_id, flags=re.IGNORECASE)matching_extractors = [e for e in gen_extractor_classes() if rex.search(e.IE_NAME)]