2015-04-11 00:17:43 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-10-12 21:56:44 +02:00
|
|
|
|
2015-04-11 00:17:43 +02:00
|
|
|
# Copyright 2014, 2015 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 image-urls from http://gelbooru.com/"""
|
|
|
|
|
2015-11-21 02:40:30 +01:00
|
|
|
from . import booru
|
2015-11-06 14:14:29 +01:00
|
|
|
from .. import config
|
2015-04-11 00:17:43 +02: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/"
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
self.params.update({"page":"dapi", "s":"post", "q":"index"})
|
2015-11-06 14:14:29 +01:00
|
|
|
self.session.cookies.update(
|
2015-11-21 02:40:30 +01:00
|
|
|
config.get(("extractor", self.category, "cookies"))
|
2015-11-06 14:14:29 +01:00
|
|
|
)
|
2014-10-12 21:56:44 +02:00
|
|
|
|
|
|
|
def update_page(self, reset=False):
|
|
|
|
if reset is False:
|
|
|
|
self.params["pid"] += 1
|
|
|
|
else:
|
2015-04-11 16:22:15 +02:00
|
|
|
self.params["pid"] = 0
|
2015-11-21 02:40:30 +01:00
|
|
|
|
|
|
|
class GelbooruTagExtractor(GelbooruExtractor, booru.BooruTagExtractor):
|
|
|
|
"""Extract images from gelbooru based on search-tags"""
|
2015-11-30 01:11:13 +01:00
|
|
|
subcategory = "tag"
|
2015-11-21 02:40:30 +01:00
|
|
|
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"""
|
2015-11-30 01:11:13 +01:00
|
|
|
# subcategory = "pool"
|
2015-11-21 02:40:30 +01:00
|
|
|
# pattern = [r"(?:https?://)?(?:www\.)?gelbooru\.com/(?:index\.php)?\?page=pool&s=show&id=(\d+)"]
|
|
|
|
|
|
|
|
class GelbooruPostExtractor(GelbooruExtractor, booru.BooruPostExtractor):
|
|
|
|
"""Extract single images from gelbooru"""
|
2015-11-30 01:11:13 +01:00
|
|
|
subcategory = "post"
|
2015-11-21 02:40:30 +01:00
|
|
|
pattern = [r"(?:https?://)?(?:www\.)?gelbooru\.com/(?:index\.php)?\?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", {
|
|
|
|
"url": "9154c1edad734f0bacd2445c5b7540804b59f2ef",
|
|
|
|
})]
|