1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 04:02:32 +01:00

[gelbooru] update to new format

This commit is contained in:
Mike Fährmann 2015-11-21 02:40:30 +01:00
parent 63a38edd05
commit bb8f2a3e9d
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 25 additions and 17 deletions

View File

@ -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.

View File

@ -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+)"]