From 02e18f56bedd66cac0911a150a16cd9793aa4647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 4 Feb 2022 02:46:32 +0100 Subject: [PATCH] [e621] add 'favorite' extractor (closes #2250) --- docs/supportedsites.md | 2 +- gallery_dl/extractor/e621.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/supportedsites.md b/docs/supportedsites.md index 5e2fc59e..8d412f6e 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -148,7 +148,7 @@ Consider all sites to be NSFW unless otherwise known. e621 https://e621.net/ - Pools, Popular Images, Posts, Tag Searches + Favorites, Pools, Popular Images, Posts, Tag Searches Supported diff --git a/gallery_dl/extractor/e621.py b/gallery_dl/extractor/e621.py index 4ad19cdb..213178c9 100644 --- a/gallery_dl/extractor/e621.py +++ b/gallery_dl/extractor/e621.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2014-2020 Mike Fährmann +# Copyright 2014-2022 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 @@ -10,6 +10,7 @@ from .common import Extractor, Message from . import danbooru +from .. import text BASE_PATTERN = r"(?:https?://)?e(621|926)\.net" @@ -119,3 +120,30 @@ class E621PopularExtractor(E621Extractor, danbooru.DanbooruPopularExtractor): "count": ">= 70", }) ) + + +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", + }) + ) + + def __init__(self, match): + super().__init__(match) + self.query = text.parse_query(match.group(2)) + + 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)