From be30fb2f98a2458b790bbeedda540ea032406b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 29 Aug 2017 22:42:48 +0200 Subject: [PATCH] add common config category for boorus and foolslide --- gallery_dl/extractor/booru.py | 7 ++++--- gallery_dl/extractor/chan.py | 16 ++++------------ gallery_dl/extractor/common.py | 13 +++++++++++++ gallery_dl/extractor/foolslide.py | 9 +++++---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/gallery_dl/extractor/booru.py b/gallery_dl/extractor/booru.py index c9433a01..3bea3ac9 100644 --- a/gallery_dl/extractor/booru.py +++ b/gallery_dl/extractor/booru.py @@ -8,15 +8,16 @@ """Base classes for extractors for danbooru and co""" -from .common import Extractor, Message +from .common import SharedConfigExtractor, Message from .. import text import xml.etree.ElementTree as ET import urllib.parse import datetime -class BooruExtractor(Extractor): +class BooruExtractor(SharedConfigExtractor): """Base class for all booru extractors""" + basecategory = "booru" filename_fmt = "{category}_{id}_{md5}.{extension}" headers = {} pagestart = 1 @@ -24,7 +25,7 @@ class BooruExtractor(Extractor): api_url = "" def __init__(self): - Extractor.__init__(self) + SharedConfigExtractor.__init__(self) self.session.headers.update(self.headers) self.params = {"limit": 50} self.setup() diff --git a/gallery_dl/extractor/chan.py b/gallery_dl/extractor/chan.py index 707d484e..ae38a9f3 100644 --- a/gallery_dl/extractor/chan.py +++ b/gallery_dl/extractor/chan.py @@ -8,7 +8,7 @@ """Base classes for extractors for different Futaba Channel-like boards""" -from .common import Extractor, Message +from .common import Extractor, SharedConfigExtractor, Message from .. import text import itertools import operator @@ -62,9 +62,9 @@ class ChanThreadExtractor(Extractor): return text.unescape(title)[:50] -class FoolfuukaThreadExtractor(Extractor): +class FoolfuukaThreadExtractor(SharedConfigExtractor): """Base extractor for FoolFuuka based boards/archives""" - category = "foolfuuka" + basecategory = "foolfuuka" subcategory = "thread" directory_fmt = ["{category}", "{board[shortname]}", "{thread_num} - {title}"] @@ -72,19 +72,11 @@ class FoolfuukaThreadExtractor(Extractor): root = "" def __init__(self, match): - Extractor.__init__(self) + SharedConfigExtractor.__init__(self) self.board, self.thread = match.groups() self.session.headers["User-Agent"] = "Mozilla 5.0" self.session.headers["Referer"] = self.root - def config(self, key, default=None, sentinel=object()): - value = Extractor.config(self, key, sentinel) - if value is sentinel: - cat, self.category = self.category, "foolfuuka" - value = Extractor.config(self, key, default) - self.category = cat - return value - def items(self): op = True yield Message.Version, 1 diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 865a6fa4..116fc36b 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -175,6 +175,19 @@ class MangaExtractor(Extractor): return [] +class SharedConfigExtractor(Extractor): + + basecategory = "" + + def config(self, key, default=None, sentinel=object()): + value = Extractor.config(self, key, sentinel) + if value is sentinel: + cat, self.category = self.category, self.basecategory + value = Extractor.config(self, key, default) + self.category = cat + return value + + # Reduce strictness of the expected magic string in cookiejar files. # (This allows the use of Wget-generated cookiejars without modification) diff --git a/gallery_dl/extractor/foolslide.py b/gallery_dl/extractor/foolslide.py index 3cc762db..fd0e3545 100644 --- a/gallery_dl/extractor/foolslide.py +++ b/gallery_dl/extractor/foolslide.py @@ -8,7 +8,7 @@ """Base classes for extractors for FoOlSlide based sites""" -from .common import Extractor, MangaExtractor, Message +from .common import SharedConfigExtractor, MangaExtractor, Message from .. import text, util import json @@ -34,8 +34,9 @@ def manga_pattern(domain_re): return [r"(?:https?://)?(" + domain_re + MANGA_RE] -class FoolslideChapterExtractor(Extractor): +class FoolslideChapterExtractor(SharedConfigExtractor): """Base class for chapter extractors for FoOlSlide based sites""" + basecategory = "foolslide" subcategory = "chapter" directory_fmt = ["{category}", "{manga}", "{chapter_string}"] filename_fmt = "{manga}_{chapter:>03}_{page:>03}.{extension}" @@ -43,7 +44,7 @@ class FoolslideChapterExtractor(Extractor): single = True def __init__(self, match, url=None): - Extractor.__init__(self) + SharedConfigExtractor.__init__(self) self.url = url or self.scheme + "://" + match.group(1) self.data = match.groupdict(default="") @@ -94,7 +95,7 @@ class FoolslideChapterExtractor(Extractor): return json.loads(text.extract(page, needle, ";", pos)[0]) -class FoolslideMangaExtractor(MangaExtractor): +class FoolslideMangaExtractor(MangaExtractor, SharedConfigExtractor): """Base class for manga extractors for FoOlSlide based sites""" scheme = "https"