2015-04-11 00:17:43 +02:00
|
|
|
# -*- 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
|
2015-04-11 00:17:43 +02:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2017-04-20 13:20:41 +02:00
|
|
|
"""Extract images from https://gelbooru.com/"""
|
2015-04-11 00:17:43 +02:00
|
|
|
|
2015-11-21 02:40:30 +01:00
|
|
|
from . import booru
|
2015-04-11 00:17:43 +02:00
|
|
|
|
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"
|
2017-04-20 13:20:41 +02:00
|
|
|
api_url = "https://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"})
|
2016-07-20 13:14:02 +02:00
|
|
|
try:
|
2017-04-25 17:12:48 +02:00
|
|
|
cookies = self.config("cookies")
|
2016-07-20 13:14:02 +02:00
|
|
|
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):
|
2016-09-12 10:20:57 +02:00
|
|
|
"""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):
|
2016-09-12 10:20:57 +02:00
|
|
|
# """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):
|
2016-09-12 10:20:57 +02:00
|
|
|
"""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
|
|
|
})]
|