59 lines
2.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2014-10-12 21:56:44 +02:00
2017-03-04 23:21:55 +01:00
# Copyright 2014-2017 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
"""Extract images from http://gelbooru.com/"""
2015-11-21 02:40:30 +01:00
from . import booru
from .. import config
2017-02-01 00:53:19 +01:00
2015-11-21 02:40:30 +01:00
class GelbooruExtractor(booru.XMLBooruExtractor):
"""Base class for gelbooru extractors"""
category = "gelbooru"
api_url = "http://gelbooru.com/"
2017-03-04 23:21:55 +01:00
pagestart = 0
pagekey = "pid"
2015-11-21 02:40:30 +01:00
def setup(self):
2017-02-01 00:53:19 +01:00
self.params.update({"page": "dapi", "s": "post", "q": "index"})
try:
cookies = config.get(("extractor", self.category, "cookies"))
self.session.cookies.update({
key: str(value) for key, value in cookies.items()
})
except AttributeError:
pass
2014-10-12 21:56:44 +02:00
2017-02-01 00:53:19 +01:00
2015-11-21 02:40:30 +01:00
class GelbooruTagExtractor(GelbooruExtractor, booru.BooruTagExtractor):
"""Extractor for images from gelbooru.com based on search-tags"""
2015-11-30 01:11:13 +01:00
subcategory = "tag"
2017-02-01 00:53:19 +01:00
pattern = [r"(?:https?://)?(?:www\.)?gelbooru\.com/(?:index\.php)?"
r"\?page=post&s=list&tags=([^&]+)"]
2015-12-22 03:10:52 +01:00
test = [("http://gelbooru.com/index.php?page=post&s=list&tags=bonocho", {
"content": "b196fb9f1668109d7774a0a82efea3ffdda07746",
})]
2015-11-21 02:40:30 +01:00
2017-02-01 00:53:19 +01:00
2015-11-21 02:40:30 +01:00
# TODO: find out how to access pools via gelbooru-api
# class GelbooruPoolExtractor(GelbooruExtractor, booru.BooruPoolExtractor):
# """Extractor for image-pools from gelbooru.com"""
2015-11-30 01:11:13 +01:00
# subcategory = "pool"
2017-02-01 00:53:19 +01:00
# pattern = [r"(?:https?://)?(?:www\.)?gelbooru\.com/(?:index\.php)?"
# r"\?page=pool&s=show&id=(\d+)"]
2015-11-21 02:40:30 +01:00
class GelbooruPostExtractor(GelbooruExtractor, booru.BooruPostExtractor):
"""Extractor for single images from gelbooru.com"""
2015-11-30 01:11:13 +01:00
subcategory = "post"
2017-02-01 00:53:19 +01:00
pattern = [r"(?:https?://)?(?:www\.)?gelbooru\.com/(?:index\.php)?"
r"\?page=post&s=view&id=(\d+)"]
2015-12-14 03:00:58 +01:00
test = [("http://gelbooru.com/index.php?page=post&s=view&id=313638", {
2015-12-22 03:10:52 +01:00
"content": "5e255713cbf0a8e0801dc423563c34d896bb9229",
2015-12-14 03:00:58 +01:00
})]