Skip to content

Commit

Permalink
[danbooru] add 'artist-search' extractor (#5348)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Nov 17, 2024
1 parent ca4b2a0 commit 50acf2a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 15 deletions.
8 changes: 4 additions & 4 deletions docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -1138,25 +1138,25 @@ Consider all listed sites to potentially be NSFW.
<tr>
<td>Danbooru</td>
<td>https://danbooru.donmai.us/</td>
<td>Pools, Popular Images, Posts, Tag Searches</td>
<td>Artists, Artist Searches, Pools, Popular Images, Posts, Tag Searches</td>
<td>Supported</td>
</tr>
<tr>
<td>ATFBooru</td>
<td>https://booru.allthefallen.moe/</td>
<td>Pools, Popular Images, Posts, Tag Searches</td>
<td>Artists, Artist Searches, Pools, Popular Images, Posts, Tag Searches</td>
<td>Supported</td>
</tr>
<tr>
<td>Aibooru</td>
<td>https://aibooru.online/</td>
<td>Pools, Popular Images, Posts, Tag Searches</td>
<td>Artists, Artist Searches, Pools, Popular Images, Posts, Tag Searches</td>
<td>Supported</td>
</tr>
<tr>
<td>Booruvar</td>
<td>https://booru.borvar.art/</td>
<td>Pools, Popular Images, Posts, Tag Searches</td>
<td>Artists, Artist Searches, Pools, Popular Images, Posts, Tag Searches</td>
<td>Supported</td>
</tr>

Expand Down
45 changes: 34 additions & 11 deletions gallery_dl/extractor/danbooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ def items(self):
yield Message.Directory, post
yield Message.Url, url, post

def items_artists(self):
for artist in self.artists():
artist["_extractor"] = DanbooruTagExtractor
url = "{}/posts?tags={}".format(
self.root, text.quote(artist["name"]))
yield Message.Queue, url, artist

def metadata(self):
return ()

Expand Down Expand Up @@ -302,15 +309,31 @@ class DanbooruArtistExtractor(DanbooruExtractor):
pattern = BASE_PATTERN + r"/artists/(\d+)"
example = "https://danbooru.donmai.us/artists/12345"

def items(self):
items = DanbooruExtractor.items_artists

def artists(self):
url = "{}/artists/{}.json".format(self.root, self.groups[-1])
artist = self.request(url).json()

url = "{}/posts?tags={}".format(
self.root, text.quote(artist["name"]))
data = {
"_extractor": DanbooruTagExtractor,
"artist" : artist,
}
yield Message.Directory, data
yield Message.Queue, url, data
return (self.request(url).json(),)


class DanbooruArtistSearchExtractor(DanbooruExtractor):
"""Extractor for danbooru artist searches"""
subcategory = "artist-search"
pattern = BASE_PATTERN + r"/artists/?\?([^#]+)"
example = "https://danbooru.donmai.us/artists?QUERY"

items = DanbooruExtractor.items_artists

def artists(self):
url = self.root + "/artists.json"
params = text.parse_query(self.groups[-1])
params["page"] = text.parse_int(params.get("page"), 1)

while True:
artists = self.request(url, params=params).json()

yield from artists

if len(artists) < 20:
return
params["page"] += 1
3 changes: 3 additions & 0 deletions scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@
"discord-server": "",
"posts" : "",
},
"Danbooru": {
"artist-search": "Artist Searches",
},
"desktopography": {
"site": "",
},
Expand Down
36 changes: 36 additions & 0 deletions test/results/danbooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,40 @@
"#count" : 120,
},

{
"#url" : "https://danbooru.donmai.us/artists/288683",
"#category": ("Danbooru", "danbooru", "artist"),
"#class" : danbooru.DanbooruArtistExtractor,
"#urls" : "https://danbooru.donmai.us/posts?tags=kaori_%28vuoian_appxv%29",

"created_at" : "2022-05-12T16:00:40.852-04:00",
"updated_at" : "2022-05-12T22:10:51.917-04:00",
"group_name" : "",
"id" : 288683,
"is_banned" : False,
"is_deleted" : False,
"name" : "kaori_(vuoian_appxv)",
"other_names": [
"香",
"vuoian_appxv",
],
},

{
"#url" : "https://danbooru.donmai.us/artists?commit=Search&search%5Bany_name_matches%5D=yu&search%5Border%5D=created_at",
"#category": ("Danbooru", "danbooru", "artist-search"),
"#class" : danbooru.DanbooruArtistSearchExtractor,
"#pattern" : danbooru.DanbooruTagExtractor.pattern,
"#count" : "> 50",

"created_at" : str,
"updated_at" : str,
"group_name" : str,
"id" : int,
"is_banned" : bool,
"is_deleted" : bool,
"name" : str,
"other_names": list,
},

)

0 comments on commit 50acf2a

Please sign in to comment.