diff --git a/gallery_dl/extractor/booru.py b/gallery_dl/extractor/booru.py index 7f50bf10..b5d7323e 100644 --- a/gallery_dl/extractor/booru.py +++ b/gallery_dl/extractor/booru.py @@ -17,7 +17,6 @@ import urllib.parse class BooruExtractor(Extractor): info = {} - params = {"limit": 50} headers = {} page = "page" api_url = "" @@ -26,6 +25,7 @@ class BooruExtractor(Extractor): def __init__(self): Extractor.__init__(self) self.params = {"limit": 50} + self.setup() def items(self): yield Message.Version, 1 @@ -40,6 +40,9 @@ class BooruExtractor(Extractor): def items_impl(self): pass + def setup(self): + pass + def update_page(self, reset=False): """Update the value of the 'page' parameter""" # Override this method in derived classes if necessary. diff --git a/gallery_dl/extractor/gelbooru.py b/gallery_dl/extractor/gelbooru.py index 11a67f0c..bcf6acee 100644 --- a/gallery_dl/extractor/gelbooru.py +++ b/gallery_dl/extractor/gelbooru.py @@ -8,27 +8,19 @@ """Extract image-urls from http://gelbooru.com/""" -from .booru import XMLBooruExtractor +from . import booru from .. import config -info = { - "category": "gelbooru", - "extractor": "GelbooruExtractor", - "directory": ["{category}", "{tags}"], - "filename": "{category}_{id}_{md5}.{extension}", - "pattern": [ - r"(?:https?://)?(?:www\.)?gelbooru\.com/(?:index\.php)?\?page=post&s=list&tags=([^&]+).*", - ], -} +class GelbooruExtractor(booru.XMLBooruExtractor): + """Base class for gelbooru extractors""" -class GelbooruExtractor(XMLBooruExtractor): + category = "gelbooru" + api_url = "http://gelbooru.com/" - def __init__(self, match): - XMLBooruExtractor.__init__(self, match, info) - self.api_url = "http://gelbooru.com/" - self.params = {"page":"dapi", "s":"post", "q":"index", "tags":self.tags} + def setup(self): + self.params.update({"page":"dapi", "s":"post", "q":"index"}) self.session.cookies.update( - config.get(("extractor", info["category"], "cookies")) + config.get(("extractor", self.category, "cookies")) ) def update_page(self, reset=False): @@ -36,3 +28,16 @@ class GelbooruExtractor(XMLBooruExtractor): self.params["pid"] += 1 else: self.params["pid"] = 0 + +class GelbooruTagExtractor(GelbooruExtractor, booru.BooruTagExtractor): + """Extract images from gelbooru based on search-tags""" + pattern = [r"(?:https?://)?(?:www\.)?gelbooru\.com/(?:index\.php)?\?page=post&s=list&tags=([^&]+)"] + +# TODO: find out how to access pools via gelbooru-api +# class GelbooruPoolExtractor(GelbooruExtractor, booru.BooruPoolExtractor): + # """Extract image-pools from gelbooru""" + # pattern = [r"(?:https?://)?(?:www\.)?gelbooru\.com/(?:index\.php)?\?page=pool&s=show&id=(\d+)"] + +class GelbooruPostExtractor(GelbooruExtractor, booru.BooruPostExtractor): + """Extract single images from gelbooru""" + pattern = [r"(?:https?://)?(?:www\.)?gelbooru\.com/(?:index\.php)?\?page=post&s=view&id=(\d+)"]