From 974e73bdbbccad11a005478250516db2dd02b4ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 6 Jan 2018 17:48:49 +0100 Subject: [PATCH] [booru] smaller code adjustments --- gallery_dl/extractor/3dbooru.py | 4 +--- gallery_dl/extractor/booru.py | 29 +++++++++++------------------ gallery_dl/extractor/danbooru.py | 4 +--- gallery_dl/extractor/e621.py | 4 +--- gallery_dl/extractor/konachan.py | 4 +--- gallery_dl/extractor/yandere.py | 4 +--- 6 files changed, 16 insertions(+), 33 deletions(-) diff --git a/gallery_dl/extractor/3dbooru.py b/gallery_dl/extractor/3dbooru.py index 3cad8363a3..c47036ebe7 100644 --- a/gallery_dl/extractor/3dbooru.py +++ b/gallery_dl/extractor/3dbooru.py @@ -11,9 +11,7 @@ from . import booru -class ThreedeebooruExtractor(booru.JsonParserMixin, - booru.MoebooruPageMixin, - booru.BooruExtractor): +class ThreedeebooruExtractor(booru.MoebooruPageMixin, booru.BooruExtractor): """Base class for 3dbooru extractors""" category = "3dbooru" api_url = "http://behoimi.org/post/index.json" diff --git a/gallery_dl/extractor/booru.py b/gallery_dl/extractor/booru.py index 668388088f..30bb24ec5c 100644 --- a/gallery_dl/extractor/booru.py +++ b/gallery_dl/extractor/booru.py @@ -43,7 +43,7 @@ def items(self): self.reset_page() while True: - images, count = self.parse_response( + images = self.parse_response( self.request(self.api_url, params=self.params)) for data in images: @@ -55,7 +55,7 @@ def items(self): except KeyError: continue - if count < self.per_page: + if len(images) < self.per_page: return self.update_page(data) @@ -66,27 +66,24 @@ def reset_page(self): def update_page(self, data): """Update params to point to the next page""" - def get_metadata(self): - """Collect metadata for extractor-job""" - - -class JsonParserMixin(): - """Class for JSON based API responses""" - sort = False - def parse_response(self, response): + """Parse JSON API response""" images = response.json() if self.sort: images.sort(key=operator.itemgetter("score", "id"), reverse=True) - return images, len(images) + return images + + def get_metadata(self): + """Collect metadata for extractor-job""" + return {} class XmlParserMixin(): - """Class for XML based API responses""" + """Mixin for XML based API responses""" def parse_response(self, response): root = ElementTree.fromstring(response.text) - return map(lambda x: x.attrib, root), len(root) + return [post.attrib for post in root] class DanbooruPageMixin(): @@ -98,7 +95,6 @@ def update_page(self, data): class MoebooruPageMixin(): """Pagination for Moebooru and Danbooru v1""" def update_page(self, data): - print("update:", self.params) if self.page_limit: self.params["page"] = None self.params["before_id"] = data["id"] @@ -154,19 +150,16 @@ def __init__(self, match): self.post = match.group("post") self.params["tags"] = "id:" + self.post - def get_metadata(self): - return {} - class PopularMixin(): """Extraction and metadata handling for Danbooru v2""" subcategory = "popular" directory_fmt = ["{category}", "popular", "{scale}", "{date}"] page_start = None + sort = True def __init__(self, match): super().__init__(match) - self.sort = True self.params.update(text.parse_query(match.group("query"))) def get_metadata(self, fmt="%Y-%m-%d"): diff --git a/gallery_dl/extractor/danbooru.py b/gallery_dl/extractor/danbooru.py index 4fa75cca6b..0f9529207d 100644 --- a/gallery_dl/extractor/danbooru.py +++ b/gallery_dl/extractor/danbooru.py @@ -17,9 +17,7 @@ r"\.donmai\.us") -class DanbooruExtractor(booru.JsonParserMixin, - booru.DanbooruPageMixin, - booru.BooruExtractor): +class DanbooruExtractor(booru.DanbooruPageMixin, booru.BooruExtractor): """Base class for danbooru extractors""" category = "danbooru" page_limit = 1000 diff --git a/gallery_dl/extractor/e621.py b/gallery_dl/extractor/e621.py index 97ac630fe8..770e51e763 100644 --- a/gallery_dl/extractor/e621.py +++ b/gallery_dl/extractor/e621.py @@ -11,9 +11,7 @@ from . import booru -class E621Extractor(booru.JsonParserMixin, - booru.MoebooruPageMixin, - booru.BooruExtractor): +class E621Extractor(booru.MoebooruPageMixin, booru.BooruExtractor): """Base class for e621 extractors""" category = "e621" api_url = "https://e621.net/post/index.json" diff --git a/gallery_dl/extractor/konachan.py b/gallery_dl/extractor/konachan.py index 5506ff9444..6b15ead069 100644 --- a/gallery_dl/extractor/konachan.py +++ b/gallery_dl/extractor/konachan.py @@ -11,9 +11,7 @@ from . import booru -class KonachanExtractor(booru.JsonParserMixin, - booru.MoebooruPageMixin, - booru.BooruExtractor): +class KonachanExtractor(booru.MoebooruPageMixin, booru.BooruExtractor): """Base class for konachan extractors""" category = "konachan" diff --git a/gallery_dl/extractor/yandere.py b/gallery_dl/extractor/yandere.py index 4b78dda617..29f87604f8 100644 --- a/gallery_dl/extractor/yandere.py +++ b/gallery_dl/extractor/yandere.py @@ -11,9 +11,7 @@ from . import booru -class YandereExtractor(booru.JsonParserMixin, - booru.MoebooruPageMixin, - booru.BooruExtractor): +class YandereExtractor(booru.MoebooruPageMixin, booru.BooruExtractor): """Base class for yandere extractors""" category = "yandere" api_url = "https://yande.re/post.json"