2015-04-11 00:17:06 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2019-01-09 14:08:06 +01:00
|
|
|
# Copyright 2014-2019 Mike Fährmann
|
2015-04-11 00:17:06 +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.
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2016-09-12 10:20:57 +02:00
|
|
|
"""Extract images from https://danbooru.donmai.us/"""
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2015-11-21 00:55:25 +01:00
|
|
|
from . import booru
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2018-01-04 00:51:04 +01:00
|
|
|
BASE_PATTERN = (
|
|
|
|
r"(?:https?://)?"
|
|
|
|
r"(?P<subdomain>danbooru|hijiribe|sonohara|safebooru)"
|
|
|
|
r"\.donmai\.us")
|
|
|
|
|
|
|
|
|
2018-01-06 17:48:49 +01:00
|
|
|
class DanbooruExtractor(booru.DanbooruPageMixin, booru.BooruExtractor):
|
2015-11-21 00:55:25 +01:00
|
|
|
"""Base class for danbooru extractors"""
|
|
|
|
category = "danbooru"
|
2018-01-03 23:52:01 +01:00
|
|
|
page_limit = 1000
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2018-01-04 00:51:04 +01:00
|
|
|
def __init__(self, match):
|
|
|
|
super().__init__(match)
|
|
|
|
self.subdomain = match.group("subdomain")
|
|
|
|
self.scheme = "https" if self.subdomain == "danbooru" else "http"
|
|
|
|
self.api_url = "{scheme}://{subdomain}.donmai.us/posts.json".format(
|
|
|
|
scheme=self.scheme, subdomain=self.subdomain)
|
|
|
|
|
2019-01-09 14:08:06 +01:00
|
|
|
username, api_key = self._get_auth_info()
|
|
|
|
if username:
|
|
|
|
self.log.debug("Using HTTP Basic Auth for user '%s'", username)
|
|
|
|
self.session.auth = (username, api_key)
|
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2018-01-03 23:52:01 +01:00
|
|
|
class DanbooruTagExtractor(booru.TagMixin, DanbooruExtractor):
|
2016-09-12 10:20:57 +02:00
|
|
|
"""Extractor for images from danbooru based on search-tags"""
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = BASE_PATTERN + r"/posts\?(?:[^&#]*&)*tags=(?P<tags>[^&#]+)"
|
|
|
|
test = (
|
2017-10-16 21:21:19 +02:00
|
|
|
("https://danbooru.donmai.us/posts?tags=bonocho", {
|
|
|
|
"content": "b196fb9f1668109d7774a0a82efea3ffdda07746",
|
|
|
|
}),
|
2018-03-19 11:30:21 +01:00
|
|
|
# test page transitions
|
|
|
|
("https://danbooru.donmai.us/posts?tags=canvas_%28cocktail_soft%29", {
|
|
|
|
"count": ">= 50",
|
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
("https://hijiribe.donmai.us/posts?tags=bonocho"),
|
|
|
|
("https://sonohara.donmai.us/posts?tags=bonocho"),
|
|
|
|
("https://safebooru.donmai.us/posts?tags=bonocho"),
|
|
|
|
)
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2018-01-03 23:52:01 +01:00
|
|
|
class DanbooruPoolExtractor(booru.PoolMixin, DanbooruExtractor):
|
2016-09-12 10:20:57 +02:00
|
|
|
"""Extractor for image-pools from danbooru"""
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = BASE_PATTERN + r"/pools/(?P<pool>\d+)"
|
|
|
|
test = ("https://danbooru.donmai.us/pools/7659", {
|
2015-12-22 03:10:52 +01:00
|
|
|
"content": "b16bab12bea5f7ea9e0a836bf8045f280e113d99",
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2015-11-20 20:24:15 +01:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2018-01-03 23:52:01 +01:00
|
|
|
class DanbooruPostExtractor(booru.PostMixin, DanbooruExtractor):
|
2016-09-12 10:20:57 +02:00
|
|
|
"""Extractor for single images from danbooru"""
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = BASE_PATTERN + r"/posts/(?P<post>\d+)"
|
|
|
|
test = ("https://danbooru.donmai.us/posts/294929", {
|
2015-12-22 03:10:52 +01:00
|
|
|
"content": "5e255713cbf0a8e0801dc423563c34d896bb9229",
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2017-08-24 21:24:51 +02:00
|
|
|
|
|
|
|
|
2018-01-03 23:52:01 +01:00
|
|
|
class DanbooruPopularExtractor(booru.PopularMixin, DanbooruExtractor):
|
2017-08-24 21:24:51 +02:00
|
|
|
"""Extractor for popular images from danbooru"""
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = BASE_PATTERN + r"/explore/posts/popular(?:\?(?P<query>[^#]*))?"
|
|
|
|
test = (
|
|
|
|
("https://danbooru.donmai.us/explore/posts/popular"),
|
2017-08-24 21:24:51 +02:00
|
|
|
(("https://danbooru.donmai.us/explore/posts/popular"
|
2017-08-31 15:09:18 +02:00
|
|
|
"?date=2013-06-06+03%3A34%3A22+-0400&scale=week"), {
|
2018-10-13 16:54:30 +02:00
|
|
|
"count": ">= 1",
|
2017-08-24 21:24:51 +02:00
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
)
|
2018-01-04 00:51:04 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
super().__init__(match)
|
|
|
|
urlfmt = "{scheme}://{subdomain}.donmai.us/explore/posts/popular.json"
|
|
|
|
self.api_url = urlfmt.format(
|
|
|
|
scheme=self.scheme, subdomain=self.subdomain)
|