45 lines
1.6 KiB
Python
Raw Normal View History

2015-11-06 13:52:40 +01:00
# -*- coding: utf-8 -*-
2015-11-21 02:52:04 +01:00
# Copyright 2015 Mike Fährmann
2015-11-06 13:52:40 +01: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.
"""Extract image-urls from http://safebooru.org/"""
2015-11-21 02:52:04 +01:00
from . import booru
2015-11-06 13:52:40 +01:00
2015-11-21 02:52:04 +01:00
class SafebooruExtractor(booru.XMLBooruExtractor):
"""Base class for safebooru extractors"""
2015-11-06 13:52:40 +01:00
2015-11-21 02:52:04 +01:00
category = "safebooru"
api_url = "http://safebooru.org/index.php"
2015-11-06 13:52:40 +01:00
2015-11-21 02:52:04 +01:00
def setup(self):
self.params.update({"page":"dapi", "s":"post", "q":"index"})
2015-11-06 13:52:40 +01:00
def update_page(self, reset=False):
if reset is False:
self.params["pid"] += 1
else:
self.params["pid"] = 0
2015-11-21 02:52:04 +01:00
class SafebooruTagExtractor(SafebooruExtractor, booru.BooruTagExtractor):
"""Extract images from safebooru based on search-tags"""
2015-11-30 01:11:13 +01:00
subcategory = "tag"
2015-11-21 02:52:04 +01:00
pattern = [r"(?:https?://)?(?:www\.)?safebooru\.org/(?:index\.php)?\?page=post&s=list&tags=([^&]+)"]
2015-12-22 03:10:52 +01:00
test = [("http://safebooru.org/index.php?page=post&s=list&tags=bonocho", {
"url": "c91e04ffbdf317fae95b2e160c8345503d9fb730",
"content": "e5ad4c5bf241b1def154958535bef6c2f6b733eb",
2015-12-14 03:00:58 +01:00
})]
2015-11-21 02:52:04 +01:00
class SafebooruPostExtractor(SafebooruExtractor, booru.BooruPostExtractor):
"""Extract single images from safebooru"""
2015-11-30 01:11:13 +01:00
subcategory = "post"
2015-11-21 02:52:04 +01:00
pattern = [r"(?:https?://)?(?:www\.)?safebooru\.org/(?:index\.php)?\?page=post&s=view&id=(\d+)"]
2015-12-14 03:00:58 +01:00
test = [("http://safebooru.org/index.php?page=post&s=view&id=1169132", {
"url": "bcb6047665729c7c9db243a27f41cbef9af1ecef",
"keyword": "e2d9a87a66d89eb68d3e3420075c3be3c7ca530a",
})]