2015-04-11 00:17:06 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2015-04-11 00:17:06 +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.
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2015-04-11 00:17:06 +02:00
|
|
|
"""Extract image-urls from https://danbooru.donmai.us/"""
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2015-04-11 00:17:06 +02:00
|
|
|
from .booru import JSONBooruExtractor
|
2015-11-20 20:24:15 +01:00
|
|
|
from .. import text
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2015-11-20 20:24:15 +01:00
|
|
|
class DanbooruTagExtractor(JSONBooruExtractor):
|
|
|
|
"""Extract images bsaed on search-tags"""
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2015-11-20 20:24:15 +01:00
|
|
|
info = {
|
|
|
|
"category": "danbooru",
|
|
|
|
"directory": ["{category}", "{tags}"],
|
|
|
|
"filename": "{category}_{id}_{md5}.{extension}",
|
|
|
|
}
|
|
|
|
pattern = [
|
|
|
|
r"(?:https?://)?(?:www\.)?danbooru.donmai.us/posts\?(?:utf8=%E2%9C%93&)?tags=([^&]+)",
|
|
|
|
]
|
2014-12-30 21:34:55 +01:00
|
|
|
|
2015-10-05 15:35:48 +02:00
|
|
|
def __init__(self, match):
|
2015-11-20 20:24:15 +01:00
|
|
|
JSONBooruExtractor.__init__(self)
|
2015-04-11 16:22:15 +02:00
|
|
|
self.api_url = "https://danbooru.donmai.us/posts.json"
|
2015-11-20 20:24:15 +01:00
|
|
|
self.tags = text.unquote(match.group(1))
|
|
|
|
self.params = {"tags": self.tags}
|
|
|
|
|
|
|
|
def get_job_metadata(self):
|
|
|
|
"""Collect metadata for extractor-job"""
|
|
|
|
return {
|
|
|
|
"category": self.info["category"],
|
|
|
|
"tags": self.tags,
|
|
|
|
}
|
2015-11-20 20:24:58 +01:00
|
|
|
|
|
|
|
class DanbooruPoolExtractor(JSONBooruExtractor):
|
|
|
|
"""Extract image-pools"""
|
|
|
|
|
|
|
|
info = {
|
|
|
|
"category": "danbooru",
|
|
|
|
"directory": ["{category}", "pool", "{pool}"],
|
|
|
|
"filename": "{category}_{id}_{md5}.{extension}",
|
|
|
|
}
|
|
|
|
pattern = [
|
|
|
|
r"(?:https?://)?(?:www\.)?danbooru.donmai.us/pools/(\d+)",
|
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
JSONBooruExtractor.__init__(self)
|
|
|
|
self.api_url = "https://danbooru.donmai.us/posts.json"
|
|
|
|
self.pool = match.group(1)
|
|
|
|
self.params = {"tags": "pool:" + self.pool}
|
|
|
|
|
|
|
|
def get_job_metadata(self):
|
|
|
|
"""Collect metadata for extractor-job"""
|
|
|
|
return {
|
|
|
|
"category": self.info["category"],
|
|
|
|
"pool": self.pool,
|
|
|
|
}
|