split e621 from danbooru module (#3425)

pull/3656/head
Mike Fährmann 2 years ago
parent 1ae48a54f8
commit 925b467496
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -380,6 +380,7 @@ Description
* ``atfbooru`` (*)
* ``danbooru`` (*)
* ``e621`` (*)
* ``e926`` (*)
* ``exhentai``
* ``idolcomplex``
* ``imgbb``

@ -1001,12 +1001,6 @@ Consider all sites to be NSFW unless otherwise known.
<td>Pools, Popular Images, Posts, Tag Searches</td>
<td>Supported</td>
</tr>
<tr>
<td>e621</td>
<td>https://e621.net/</td>
<td>Favorites, Pools, Popular Images, Posts, Tag Searches</td>
<td>Supported</td>
</tr>
<tr>
<td>ATFBooru</td>
<td>https://booru.allthefallen.moe/</td>
@ -1016,6 +1010,22 @@ Consider all sites to be NSFW unless otherwise known.
<tr>
<td>Aibooru</td>
<td>https://aibooru.online/</td>
<td>Pools, Popular Images, Posts, Tag Searches</td>
<td>Supported</td>
</tr>
<tr>
<td colspan="4"><strong>e621 Instances</strong></td>
</tr>
<tr>
<td>e621</td>
<td>https://e621.net/</td>
<td>Favorites, Pools, Popular Images, Posts, Tag Searches</td>
<td>Supported</td>
</tr>
<tr>
<td>e926</td>
<td>https://e926.net/</td>
<td>Favorites, Pools, Popular Images, Posts, Tag Searches</td>
<td>Supported</td>
</tr>

@ -35,6 +35,7 @@ modules = [
"desktopography",
"deviantart",
"dynastyscans",
"e621",
"erome",
"exhentai",
"fallenangels",

@ -9,7 +9,6 @@
"""Extractors for https://danbooru.donmai.us/ and other Danbooru instances"""
from .common import BaseExtractor, Message
from ..version import __version__
from .. import text
import datetime
@ -23,21 +22,7 @@ class DanbooruExtractor(BaseExtractor):
per_page = 200
def __init__(self, match):
self._init_category(match)
instance = INSTANCES.get(self.category) or {}
iget = instance.get
self.headers = iget("headers")
self.page_limit = iget("page-limit", 1000)
self.page_start = iget("page-start")
self.per_page = iget("per-page", 200)
self.request_interval_min = iget("request-interval-min", 0.0)
self._pools = iget("pools")
self._popular_endpoint = iget("popular", "/explore/posts/popular.json")
BaseExtractor.__init__(self, match)
self.ugoira = self.config("ugoira", False)
self.external = self.config("external", False)
@ -62,10 +47,6 @@ class DanbooruExtractor(BaseExtractor):
self.log.debug("Using HTTP Basic Auth for user '%s'", username)
self.session.auth = (username, api_key)
def request(self, url, **kwargs):
kwargs["headers"] = self.headers
return BaseExtractor.request(self, url, **kwargs)
def skip(self, num):
pages = num // self.per_page
if pages >= self.page_limit:
@ -77,29 +58,16 @@ class DanbooruExtractor(BaseExtractor):
data = self.metadata()
for post in self.posts():
file = post.get("file")
if file:
url = file["url"]
if not url:
md5 = file["md5"]
url = file["url"] = (
"https://static1.{}/data/{}/{}/{}.{}".format(
self.root[8:], md5[0:2], md5[2:4], md5, file["ext"]
))
post["filename"] = file["md5"]
post["extension"] = file["ext"]
else:
try:
url = post["file_url"]
except KeyError:
if self.external and post["source"]:
post.update(data)
yield Message.Directory, post
yield Message.Queue, post["source"], post
continue
try:
url = post["file_url"]
except KeyError:
if self.external and post["source"]:
post.update(data)
yield Message.Directory, post
yield Message.Queue, post["source"], post
continue
text.nameext_from_url(url, post)
text.nameext_from_url(url, post)
if post["extension"] == "zip":
if self.ugoira:
@ -127,7 +95,7 @@ class DanbooruExtractor(BaseExtractor):
def posts(self):
return ()
def _pagination(self, endpoint, params, pagenum=False):
def _pagination(self, endpoint, params, pages=False):
url = self.root + endpoint
params["limit"] = self.per_page
params["page"] = self.page_start
@ -141,7 +109,7 @@ class DanbooruExtractor(BaseExtractor):
if len(posts) < self.threshold:
return
if pagenum:
if pages:
params["page"] += 1
else:
for post in reversed(posts):
@ -163,34 +131,20 @@ class DanbooruExtractor(BaseExtractor):
for index, delay in enumerate(delays)]
INSTANCES = {
BASE_PATTERN = DanbooruExtractor.update({
"danbooru": {
"root": None,
"pattern": r"(?:danbooru|hijiribe|sonohara|safebooru)\.donmai\.us",
},
"e621": {
"root": None,
"pattern": r"e(?:621|926)\.net",
"headers": {"User-Agent": "gallery-dl/{} (by mikf)".format(
__version__)},
"pools": "sort",
"popular": "/popular.json",
"page-limit": 750,
"per-page": 320,
"request-interval-min": 1.0,
},
"atfbooru": {
"root": "https://booru.allthefallen.moe",
"pattern": r"booru\.allthefallen\.moe",
"page-limit": 5000,
},
"aibooru": {
"root": None,
"pattern": r"(?:safe.)?aibooru\.online",
}
}
BASE_PATTERN = DanbooruExtractor.update(INSTANCES)
})
class DanbooruTagExtractor(DanbooruExtractor):
@ -213,10 +167,6 @@ class DanbooruTagExtractor(DanbooruExtractor):
"pattern": r"https://i\.pximg\.net/img-original/img"
r"/2008/08/28/02/35/48/1476533_p0\.jpg",
}),
("https://e621.net/posts?tags=anry", {
"url": "8021e5ea28d47c474c1ffc9bd44863c4d45700ba",
"content": "501d1e5d922da20ee8ff9806f5ed3ce3a684fd58",
}),
("https://booru.allthefallen.moe/posts?tags=yume_shokunin", {
"count": 12,
}),
@ -228,7 +178,6 @@ class DanbooruTagExtractor(DanbooruExtractor):
("https://hijiribe.donmai.us/posts?tags=bonocho"),
("https://sonohara.donmai.us/posts?tags=bonocho"),
("https://safebooru.donmai.us/posts?tags=bonocho"),
("https://e926.net/posts?tags=anry"),
("https://safe.aibooru.online/posts?tags=center_frills"),
)
@ -254,23 +203,17 @@ class DanbooruPoolExtractor(DanbooruExtractor):
("https://danbooru.donmai.us/pools/7659", {
"content": "b16bab12bea5f7ea9e0a836bf8045f280e113d99",
}),
("https://e621.net/pools/73", {
"url": "1bd09a72715286a79eea3b7f09f51b3493eb579a",
"content": "91abe5d5334425d9787811d7f06d34c77974cd22",
}),
("https://booru.allthefallen.moe/pools/9", {
"url": "902549ffcdb00fe033c3f63e12bc3cb95c5fd8d5",
"count": 6,
}),
("https://aibooru.online/pools/1"),
("https://danbooru.donmai.us/pool/show/7659"),
("https://e621.net/pool/show/73"),
)
def __init__(self, match):
DanbooruExtractor.__init__(self, match)
self.pool_id = match.group(match.lastindex)
self.post_ids = ()
def metadata(self):
url = "{}/pools/{}.json".format(self.root, self.pool_id)
@ -280,29 +223,8 @@ class DanbooruPoolExtractor(DanbooruExtractor):
return {"pool": pool}
def posts(self):
if self._pools == "sort":
self.log.info("Fetching posts of pool %s", self.pool_id)
id_to_post = {
post["id"]: post
for post in self._pagination(
"/posts.json", {"tags": "pool:" + self.pool_id})
}
posts = []
append = posts.append
for num, pid in enumerate(self.post_ids, 1):
if pid in id_to_post:
post = id_to_post[pid]
post["num"] = num
append(post)
else:
self.log.warning("Post %s is unavailable", pid)
return posts
else:
params = {"tags": "pool:" + self.pool_id}
return self._pagination("/posts.json", params)
params = {"tags": "pool:" + self.pool_id}
return self._pagination("/posts.json", params)
class DanbooruPostExtractor(DanbooruExtractor):
@ -318,10 +240,6 @@ class DanbooruPostExtractor(DanbooruExtractor):
"pattern": r"https?://.+\.zip$",
"options": (("ugoira", True),)
}),
("https://e621.net/posts/535", {
"url": "f7f78b44c9b88f8f09caac080adc8d6d9fdaa529",
"content": "66f46e96a893fba8e694c4e049b23c2acc9af462",
}),
("https://booru.allthefallen.moe/posts/22", {
"content": "21dda68e1d7e0a554078e62923f537d8e895cac8",
}),
@ -329,7 +247,6 @@ class DanbooruPostExtractor(DanbooruExtractor):
"content": "54d548743cd67799a62c77cbae97cfa0fec1b7e9",
}),
("https://danbooru.donmai.us/post/show/294929"),
("https://e621.net/post/show/535"),
)
def __init__(self, match):
@ -338,8 +255,7 @@ class DanbooruPostExtractor(DanbooruExtractor):
def posts(self):
url = "{}/posts/{}.json".format(self.root, self.post_id)
post = self.request(url).json()
return (post["post"] if "post" in post else post,)
return (self.request(url).json(),)
class DanbooruPopularExtractor(DanbooruExtractor):
@ -355,12 +271,6 @@ class DanbooruPopularExtractor(DanbooruExtractor):
"range": "1-120",
"count": 120,
}),
("https://e621.net/popular"),
(("https://e621.net/explore/posts/popular"
"?date=2019-06-01&scale=month"), {
"pattern": r"https://static\d.e621.net/data/../../[0-9a-f]+",
"count": ">= 70",
}),
("https://booru.allthefallen.moe/explore/posts/popular"),
("https://aibooru.online/explore/posts/popular"),
)
@ -385,31 +295,5 @@ class DanbooruPopularExtractor(DanbooruExtractor):
def posts(self):
if self.page_start is None:
self.page_start = 1
return self._pagination(self._popular_endpoint, self.params, True)
class DanbooruFavoriteExtractor(DanbooruExtractor):
"""Extractor for e621 favorites"""
subcategory = "favorite"
directory_fmt = ("{category}", "Favorites", "{user_id}")
archive_fmt = "f_{user_id}_{id}"
pattern = BASE_PATTERN + r"/favorites(?:\?([^#]*))?"
test = (
("https://e621.net/favorites"),
("https://e621.net/favorites?page=2&user_id=53275", {
"pattern": r"https://static\d.e621.net/data/../../[0-9a-f]+",
"count": "> 260",
}),
)
def __init__(self, match):
DanbooruExtractor.__init__(self, match)
self.query = text.parse_query(match.group(match.lastindex))
def metadata(self):
return {"user_id": self.query.get("user_id", "")}
def posts(self):
if self.page_start is None:
self.page_start = 1
return self._pagination("/favorites.json", self.query, True)
return self._pagination(
"/explore/posts/popular.json", self.params, True)

@ -0,0 +1,196 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2023 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.
"""Extractors for https://e621.net/ and other e621 instances"""
from .common import Extractor, Message
from . import danbooru
from .. import text, version
class E621Extractor(danbooru.DanbooruExtractor):
"""Base class for e621 extractors"""
basecategory = "E621"
page_limit = 750
page_start = None
per_page = 320
request_interval_min = 1.0
def request(self, url, **kwargs):
kwargs["headers"] = self.headers
return Extractor.request(self, url, **kwargs)
def items(self):
self.headers = {"User-Agent": "gallery-dl/{} (by mikf)".format(
version.__version__)}
data = self.metadata()
for post in self.posts():
file = post["file"]
if not file["url"]:
md5 = file["md5"]
file["url"] = "https://static1.{}/data/{}/{}/{}.{}".format(
self.root[8:], md5[0:2], md5[2:4], md5, file["ext"])
post["filename"] = file["md5"]
post["extension"] = file["ext"]
post.update(data)
yield Message.Directory, post
yield Message.Url, file["url"], post
BASE_PATTERN = E621Extractor.update({
"e621": {
"root": "https://e621.net",
"pattern": r"e621\.net",
},
"e926": {
"root": "https://e926.net",
"pattern": r"e926\.net",
},
})
class E621TagExtractor(E621Extractor, danbooru.DanbooruTagExtractor):
"""Extractor for e621 posts from tag searches"""
pattern = BASE_PATTERN + r"/posts?(?:\?.*?tags=|/index/\d+/)([^&#]+)"
test = (
("https://e621.net/posts?tags=anry", {
"url": "8021e5ea28d47c474c1ffc9bd44863c4d45700ba",
"content": "501d1e5d922da20ee8ff9806f5ed3ce3a684fd58",
}),
("https://e621.net/post/index/1/anry"),
("https://e621.net/post?tags=anry"),
("https://e926.net/posts?tags=anry", {
"url": "12198b275c62ffe2de67cca676c8e64de80c425d",
"content": "501d1e5d922da20ee8ff9806f5ed3ce3a684fd58",
}),
("https://e926.net/post/index/1/anry"),
("https://e926.net/post?tags=anry"),
)
class E621PoolExtractor(E621Extractor, danbooru.DanbooruPoolExtractor):
"""Extractor for e621 pools"""
pattern = BASE_PATTERN + r"/pool(?:s|/show)/(\d+)"
test = (
("https://e621.net/pools/73", {
"url": "1bd09a72715286a79eea3b7f09f51b3493eb579a",
"content": "91abe5d5334425d9787811d7f06d34c77974cd22",
}),
("https://e621.net/pool/show/73"),
("https://e926.net/pools/73", {
"url": "6936f1b6a18c5c25bee7cad700088dbc2503481b",
"content": "91abe5d5334425d9787811d7f06d34c77974cd22",
}),
("https://e926.net/pool/show/73"),
)
def posts(self):
self.log.info("Fetching posts of pool %s", self.pool_id)
id_to_post = {
post["id"]: post
for post in self._pagination(
"/posts.json", {"tags": "pool:" + self.pool_id})
}
posts = []
append = posts.append
for num, pid in enumerate(self.post_ids, 1):
if pid in id_to_post:
post = id_to_post[pid]
post["num"] = num
append(post)
else:
self.log.warning("Post %s is unavailable", pid)
return posts
class E621PostExtractor(E621Extractor, danbooru.DanbooruPostExtractor):
"""Extractor for single e621 posts"""
pattern = BASE_PATTERN + r"/post(?:s|/show)/(\d+)"
test = (
("https://e621.net/posts/535", {
"url": "f7f78b44c9b88f8f09caac080adc8d6d9fdaa529",
"content": "66f46e96a893fba8e694c4e049b23c2acc9af462",
}),
("https://e621.net/post/show/535"),
("https://e926.net/posts/535", {
"url": "17aec8ebd8fab098d321adcb62a2db59dab1f4bf",
"content": "66f46e96a893fba8e694c4e049b23c2acc9af462",
}),
("https://e926.net/post/show/535"),
)
def posts(self):
url = "{}/posts/{}.json".format(self.root, self.post_id)
return (self.request(url).json()["post"],)
class E621PopularExtractor(E621Extractor, danbooru.DanbooruPopularExtractor):
"""Extractor for popular images from e621"""
pattern = BASE_PATTERN + r"/explore/posts/popular(?:\?([^#]*))?"
test = (
("https://e621.net/explore/posts/popular"),
(("https://e621.net/explore/posts/popular"
"?date=2019-06-01&scale=month"), {
"pattern": r"https://static\d.e621.net/data/../../[0-9a-f]+",
"count": ">= 70",
}),
("https://e926.net/explore/posts/popular"),
(("https://e926.net/explore/posts/popular"
"?date=2019-06-01&scale=month"), {
"pattern": r"https://static\d.e926.net/data/../../[0-9a-f]+",
"count": ">= 70",
}),
)
def posts(self):
if self.page_start is None:
self.page_start = 1
return self._pagination("/popular.json", self.params, True)
class E621FavoriteExtractor(E621Extractor):
"""Extractor for e621 favorites"""
subcategory = "favorite"
directory_fmt = ("{category}", "Favorites", "{user_id}")
archive_fmt = "f_{user_id}_{id}"
pattern = BASE_PATTERN + r"/favorites(?:\?([^#]*))?"
test = (
("https://e621.net/favorites"),
("https://e621.net/favorites?page=2&user_id=53275", {
"pattern": r"https://static\d.e621.net/data/../../[0-9a-f]+",
"count": "> 260",
}),
("https://e926.net/favorites"),
("https://e926.net/favorites?page=2&user_id=53275", {
"pattern": r"https://static\d.e926.net/data/../../[0-9a-f]+",
"count": "> 260",
}),
)
def __init__(self, match):
E621Extractor.__init__(self, match)
self.query = text.parse_query(match.group(match.lastindex))
def metadata(self):
return {"user_id": self.query.get("user_id", "")}
def posts(self):
if self.page_start is None:
self.page_start = 1
return self._pagination("/favorites.json", self.query, True)

@ -35,6 +35,7 @@ CATEGORY_MAP = {
"drawfriends" : "Draw Friends",
"dynastyscans" : "Dynasty Reader",
"e621" : "e621",
"e926" : "e926",
"erome" : "EroMe",
"e-hentai" : "E-Hentai",
"exhentai" : "ExHentai",
@ -153,16 +154,10 @@ SUBCATEGORY_MAP = {
"artstation": {
"artwork": "Artwork Listings",
},
"atfbooru": {
"favorite": "",
},
"coomerparty": {
"discord" : "",
"discord-server": "",
},
"danbooru": {
"favorite": "",
},
"desktopography": {
"site": "",
},
@ -256,6 +251,7 @@ SUBCATEGORY_MAP = {
}
BASE_MAP = {
"E621" : "e621 Instances",
"foolfuuka" : "FoolFuuka 4chan Archives",
"foolslide" : "FoOlSlide Instances",
"gelbooru_v01": "Gelbooru Beta 0.1.11",
@ -285,6 +281,7 @@ AUTH_MAP = {
"derpibooru" : _APIKEY_DB,
"deviantart" : _OAUTH,
"e621" : "Supported",
"e926" : "Supported",
"e-hentai" : "Supported",
"exhentai" : "Supported",
"fanbox" : _COOKIES,

@ -322,9 +322,9 @@ def setup_test_config():
config.set(("extractor", "mangoxo") , "username", "LiQiang3")
config.set(("extractor", "mangoxo") , "password", "5zbQF10_5u25259Ma")
for category in ("danbooru", "instagram", "twitter", "subscribestar",
"e621", "atfbooru", "inkbunny", "tapas", "pillowfort",
"mangadex", "aibooru"):
for category in ("danbooru", "atfbooru", "aibooru", "e621", "e926",
"instagram", "twitter", "subscribestar",
"inkbunny", "tapas", "pillowfort", "mangadex"):
config.set(("extractor", category), "username", None)
config.set(("extractor", "mastodon.social"), "access-token",

Loading…
Cancel
Save