From 6a07e3836603407ee7fc17305f0ae7165b76f83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 2 Feb 2018 00:01:41 +0100 Subject: [PATCH] implement extractor.add() and .add_module() ... as a public and non-hacky way to add (external) extractors to gallery-dl's pool and make them available for extractor.find() --- gallery_dl/extractor/__init__.py | 28 ++++++++++++++++++++-------- gallery_dl/extractor/powermanga.py | 4 ++-- gallery_dl/extractor/rule34.py | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/gallery_dl/extractor/__init__.py b/gallery_dl/extractor/__init__.py index 249778f5..d9478485 100644 --- a/gallery_dl/extractor/__init__.py +++ b/gallery_dl/extractor/__init__.py @@ -103,6 +103,23 @@ def find(url): return None +def add(klass): + """Add 'klass' to the list of available extractors""" + for pattern in klass: + _cache.append((re.compile(pattern), klass)) + + +def add_module(module): + """Add all extractors in 'module' to the list of available extractors""" + tuples = [ + (re.compile(pattern), klass) + for klass in _get_classes(module) + for pattern in klass.pattern + ] + _cache.extend(tuples) + return tuples + + def extractors(): """Yield all available extractor classes""" return sorted( @@ -139,14 +156,9 @@ def _list_patterns(): yield from _cache for module_name in _module_iter: - module = importlib.import_module("."+module_name, __package__) - tuples = [ - (re.compile(pattern), klass) - for klass in _get_classes(module) - for pattern in klass.pattern - ] - _cache.extend(tuples) - yield from tuples + yield from add_module( + importlib.import_module("."+module_name, __package__) + ) def _get_classes(module): diff --git a/gallery_dl/extractor/powermanga.py b/gallery_dl/extractor/powermanga.py index 8a38d98d..96038953 100644 --- a/gallery_dl/extractor/powermanga.py +++ b/gallery_dl/extractor/powermanga.py @@ -26,6 +26,6 @@ class PowermangaMangaExtractor(foolslide.FoolslideMangaExtractor): category = "powermanga" pattern = foolslide.manga_pattern(r"read\.powermanga\.org") test = [("https://read.powermanga.org/series/one_piece/", { - "url": "6ba226780a3c1c1f1cc5f4a4b96c18260f4ec0f3", - "keyword": "576109177b1bb59ab2f55450cc9ef4a31e28714c", + "url": "3b2037a9ffe30ea0da4e710a40863f0693f21afe", + "keyword": "e2a924b0924cba711e78b3585ad24a97dec70006", })] diff --git a/gallery_dl/extractor/rule34.py b/gallery_dl/extractor/rule34.py index 6e74bf70..d07e2264 100644 --- a/gallery_dl/extractor/rule34.py +++ b/gallery_dl/extractor/rule34.py @@ -30,7 +30,7 @@ class Rule34TagExtractor(booru.TagMixin, Rule34Extractor): r"\?page=post&s=list&tags=(?P[^&#]+)")] test = [("http://rule34.xxx/index.php?page=post&s=list&tags=danraku", { "content": "a01768c6f86f32eb7ebbdeb87c30b0d9968d7f97", - "pattern": r"https?://b?img\.rule34\.xxx/images/\d+/[0-9a-f]+\.jpg", + "pattern": r"https?://(.?img\.)?rule34\.xxx/images/\d+/[0-9a-f]+\.jpg", "count": 2, })]