From 909d105ae6f786cb143fcc056e955c8f0ac787f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 15 May 2018 13:02:49 +0200 Subject: [PATCH] [pixiv] add extractor for illusts from followed users --- docs/supportedsites.rst | 4 ++-- gallery_dl/extractor/pixiv.py | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/docs/supportedsites.rst b/docs/supportedsites.rst index da6b774a..cdf5c697 100644 --- a/docs/supportedsites.rst +++ b/docs/supportedsites.rst @@ -88,8 +88,8 @@ Turboimagehost https://turboimagehost.com/ individual Images ==================== =================================== ================================================== ================ .. |Images from Use-0| replace:: Images from Users, Albums, Challenges, individual Images, Likes, Search Results -.. |Collections, De-1| replace:: Collections, Deviations, Favorites, Folders, Galleries, Journals +.. |Collections, De-1| replace:: Collections, Deviations, Favorites, Folders, Galleries, Journals, Popular Images .. |Images from Use-2| replace:: Images from Users, Albums, Favorites, Galleries, Groups, individual Images, Search Results .. |Images from Use-3| replace:: Images from Users, Doujin, Favorites, individual Images -.. |Images from Use-4| replace:: Images from Users, Bookmarks, Favorites, pixiv.me Links, Rankings, Individual Images +.. |Images from Use-4| replace:: Images from Users, Bookmarks, Favorites, Follows, pixiv.me Links, Rankings, Search Results, Individual Images .. |Albums, individ-5| replace:: Albums, individual Images, Images from Users and Folders diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index 5f278bae..7ef5b5b7 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -240,9 +240,7 @@ class PixivBookmarkExtractor(PixivFavoriteExtractor): def get_metadata(self, user=None): self.api.login() - user = self.api.user_info - self.user_id = user["id"] - return PixivFavoriteExtractor.get_metadata(self, user) + return PixivFavoriteExtractor.get_metadata(self, self.api.user) class PixivRankingExtractor(PixivExtractor): @@ -364,6 +362,29 @@ class PixivSearchExtractor(PixivExtractor): return {"search": self.search_info} +class PixivFollowExtractor(PixivExtractor): + """Extractor for new illustrations from your followed artists""" + subcategory = "follow" + archive_fmt = "F_{user_follow[id]}_{id}{num}.{extension}" + directory_fmt = ["{category}", "following"] + pattern = [r"(?:https?://)?(?:www\.|touch\.)?pixiv\.net" + r"/bookmark_new_illust\.php"] + test = [ + ("https://www.pixiv.net/bookmark_new_illust.php", None), + ("https://touch.pixiv.net/bookmark_new_illust.php", None), + ] + + def __init__(self, match): + PixivExtractor.__init__(self) + + def works(self): + return self.api.illust_follow() + + def get_metadata(self, user=None): + self.api.login() + return {"user_follow": self.api.user} + + class PixivAppAPI(): """Minimal interface for the Pixiv App API for mobile devices @@ -378,7 +399,7 @@ class PixivAppAPI(): self.session = extractor.session self.log = extractor.log self.username, self.password = extractor._get_auth_info() - self.user_info = None + self.user = None self.client_id = extractor.config( "client-id", self.CLIENT_ID) @@ -395,7 +416,7 @@ class PixivAppAPI(): def login(self): """Login and gain an access token""" - self.user_info, auth = self._login_impl( + self.user, auth = self._login_impl( self.username, self.password) self.session.headers["Authorization"] = auth @@ -424,6 +445,10 @@ class PixivAppAPI(): params = {"illust_id": illust_id} return self._call("v1/illust/detail", params)["illust"] + def illust_follow(self, restrict="all"): + params = {"restrict": restrict} + return self._pagination("v2/illust/follow", params) + def illust_ranking(self, mode="day", date=None): params = {"mode": mode, "date": date} return self._pagination("v1/illust/ranking", params)