diff --git a/gallery_dl/downloader/ytdl.py b/gallery_dl/downloader/ytdl.py index 87e77562..b3bec210 100644 --- a/gallery_dl/downloader/ytdl.py +++ b/gallery_dl/downloader/ytdl.py @@ -42,8 +42,9 @@ class YoutubeDLDownloader(DownloaderBase): if not ytdl_instance: try: module = ytdl.import_module(self.config("module")) - except ImportError as exc: - self.log.error("Cannot import module '%s'", exc.name) + except (ImportError, SyntaxError) as exc: + self.log.error("Cannot import module '%s'", + getattr(exc, "name", "")) self.log.debug("", exc_info=True) self.download = lambda u, p: False return False diff --git a/gallery_dl/ytdl.py b/gallery_dl/ytdl.py index d4fdedc4..fe88c2cb 100644 --- a/gallery_dl/ytdl.py +++ b/gallery_dl/ytdl.py @@ -18,7 +18,7 @@ def import_module(module_name): if module_name is None: try: return __import__("yt_dlp") - except ImportError: + except (ImportError, SyntaxError): return __import__("youtube_dl") return __import__(module_name.replace("-", "_")) diff --git a/test/test_ytdl.py b/test/test_ytdl.py index fd2e40a8..f7eb6712 100644 --- a/test/test_ytdl.py +++ b/test/test_ytdl.py @@ -22,7 +22,7 @@ class Test_CommandlineArguments(unittest.TestCase): def setUpClass(cls): try: cls.module = __import__(cls.module_name) - except ImportError: + except (ImportError, SyntaxError): raise unittest.SkipTest("cannot import module '{}'".format( cls.module_name)) cls.default = ytdl.parse_command_line(cls.module, [])