From 9a849cdf61a6b4e1c4262062a588c0f00ae03629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 12 Jul 2021 18:47:12 +0200 Subject: [PATCH] [ytdl] allow setting 'module' for subcategories (#1680) --- gallery_dl/extractor/ytdl.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gallery_dl/extractor/ytdl.py b/gallery_dl/extractor/ytdl.py index eae56d09..563caca1 100644 --- a/gallery_dl/extractor/ytdl.py +++ b/gallery_dl/extractor/ytdl.py @@ -18,15 +18,17 @@ class YoutubeDLExtractor(Extractor): directory_fmt = ("{category}", "{subcategory}") filename_fmt = "{title}-{id}.{extension}" archive_fmt = "{extractor_key} {id}" - ytdl_module = None pattern = r"ytdl:(.*)" test = ("ytdl:https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9",) + ytdl_module = None + ytdl_module_name = None def __init__(self, match): - # import youtube_dl module + # import main youtube_dl module module = self.ytdl_module if not module: - name = config.get(("extractor", "ytdl"), "module") or "youtube_dl" + name = YoutubeDLExtractor.ytdl_module_name = config.get( + ("extractor", "ytdl"), "module") or "youtube_dl" module = YoutubeDLExtractor.ytdl_module = __import__(name) # find suitable youtube_dl extractor @@ -49,6 +51,14 @@ class YoutubeDLExtractor(Extractor): Extractor.__init__(self, match) def items(self): + # check subcategory module; import and use if needed + name = config.get(("extractor", "ytdl", self.subcategory), "module") + if name and name != self.ytdl_module_name: + ytdl_module = __import__(name) + else: + ytdl_module = self.ytdl_module + self.log.debug("Using %s", ytdl_module) + # construct YoutubeDL object options = { "format": self.config("format"), @@ -70,7 +80,7 @@ class YoutubeDLExtractor(Extractor): options["username"], options["password"] = username, password del username, password - ytdl = self.ytdl_module.YoutubeDL(options) + ytdl = ytdl_module.YoutubeDL() ytdl.cookiejar = self.session.cookies # extract youtube_dl info_dict