From 7bbb1f92d7e1f82bcc4fac38d0a6995c46fab35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 10 Sep 2021 00:21:35 +0200 Subject: [PATCH] [gelbooru_v02] add 'favorite' extractor (closes #1834) --- docs/supportedsites.md | 8 ++--- gallery_dl/extractor/gelbooru_v02.py | 52 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/docs/supportedsites.md b/docs/supportedsites.md index 72cf211a65..e7662ee9bd 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -888,25 +888,25 @@ Consider all sites to be NSFW unless otherwise known. Realbooru https://realbooru.com/ - Pools, Posts, Tag Searches + Favorites, Pools, Posts, Tag Searches Rule 34 https://rule34.xxx/ - Pools, Posts, Tag Searches + Favorites, Pools, Posts, Tag Searches Safebooru https://safebooru.org/ - Pools, Posts, Tag Searches + Favorites, Pools, Posts, Tag Searches The Big ImageBoard https://tbib.org/ - Pools, Posts, Tag Searches + Favorites, Pools, Posts, Tag Searches diff --git a/gallery_dl/extractor/gelbooru_v02.py b/gallery_dl/extractor/gelbooru_v02.py index 1b877b3a3e..e09e190d8b 100644 --- a/gallery_dl/extractor/gelbooru_v02.py +++ b/gallery_dl/extractor/gelbooru_v02.py @@ -176,6 +176,58 @@ def posts(self): yield post.attrib +class GelbooruV02FavoriteExtractor(GelbooruV02Extractor): + subcategory = "favorite" + directory_fmt = ("{category}", "favorites", "{favorite_id}") + archive_fmt = "f_{favorite_id}_{id}" + per_page = 50 + pattern = BASE_PATTERN + r"/index\.php\?page=favorites&s=view&id=(\d+)" + test = ( + ("https://rule34.xxx/index.php?page=favorites&s=view&id=1030218", { + "count": 3, + }), + ("https://safebooru.org/index.php?page=favorites&s=view&id=17567", { + "count": 2, + }), + ("https://realbooru.com/index.php?page=favorites&s=view&id=274", { + "count": 4, + }), + ("https://tbib.org/index.php?page=favorites&s=view&id=7881", { + "count": 3, + }), + ) + + def __init__(self, match): + GelbooruV02Extractor.__init__(self, match) + self.favorite_id = match.group(match.lastindex) + + def metadata(self): + return {"favorite_id": text.parse_int(self.favorite_id)} + + def posts(self): + url = self.root + "/index.php" + params = { + "page": "favorites", + "s" : "view", + "id" : self.favorite_id, + "pid" : self.page_start * self.per_page, + } + + data = {} + while True: + num_ids = 0 + page = self.request(url, params=params).text + + for data["id"] in text.extract_iter(page, '" id="p', '"'): + num_ids += 1 + for post in self._api_request(data): + yield post.attrib + + if num_ids < self.per_page: + return + params["pid"] += self.per_page + + class GelbooruV02PostExtractor(GelbooruV02Extractor): subcategory = "post" archive_fmt = "{id}"