From dff0da60f94fee53895738f9efda702d60b0d82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 11 Jul 2021 23:01:57 +0200 Subject: [PATCH] [ytdl] add 'generic' option (#1680) --- docs/configuration.rst | 13 +++++++++++++ docs/gallery-dl.conf | 1 + gallery_dl/extractor/ytdl.py | 19 ++++++++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index bfdd32dc..af37d4cc 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1977,6 +1977,19 @@ Description directly passed to youtube-dl. +extractor.ytdl.generic +---------------------- +Type + ``bool`` +Default + ``true`` +Description + Controls the use of youtube-dl's generic extractor. + + Set this option to ``"force"`` for the same effect as youtube-dl's + ``--force-generic-extractor``. + + extractor.ytdl.logging ---------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index c97ecdf7..5eab0fa9 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -291,6 +291,7 @@ { "enabled": false, "format": null, + "generic": true, "logging": true, "module": "youtube_dl", "raw-options": null diff --git a/gallery_dl/extractor/ytdl.py b/gallery_dl/extractor/ytdl.py index dc092b2a..eae56d09 100644 --- a/gallery_dl/extractor/ytdl.py +++ b/gallery_dl/extractor/ytdl.py @@ -9,7 +9,7 @@ """Extractors for sites supported by youtube-dl""" from .common import Extractor, Message -from .. import config +from .. import config, exception class YoutubeDLExtractor(Extractor): @@ -31,10 +31,18 @@ class YoutubeDLExtractor(Extractor): # find suitable youtube_dl extractor self.ytdl_url = url = match.group(1) - for ie in module.extractor.gen_extractor_classes(): - if ie.suitable(url): - self.ytdl_ie = ie - break + generic = config.interpolate(("extractor", "ytdl"), "generic", True) + if generic == "force": + self.ytdl_ie = ie = module.extractor.GenericIE + self.force_generic_extractor = True + else: + for ie in module.extractor.gen_extractor_classes(): + if ie.suitable(url): + self.ytdl_ie = ie + break + if not generic and ie == module.extractor.GenericIE: + raise exception.NoExtractorError() + self.force_generic_extractor = False # set subcategory to youtube_dl extractor's key self.subcategory = ie.ie_key() @@ -47,6 +55,7 @@ class YoutubeDLExtractor(Extractor): "socket_timeout": self._timeout, "nocheckcertificate": not self._verify, "proxy": self.session.proxies.get("http"), + "force_generic_extractor": self.force_generic_extractor, } raw_options = self.config("raw-options")