From d5e2fe4f4424370066af32049aacd531555d1359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 8 Aug 2025 09:04:14 +0200 Subject: [PATCH] [pixiv] detect suspended/deleted accounts (#7990) --- gallery_dl/extractor/pixiv.py | 18 +++++++++++------- test/results/pixiv.py | 8 ++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index d2dd33a4..edea8ef0 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -1262,7 +1262,7 @@ class PixivAppAPI(): def user_illusts(self, user_id): params = {"user_id": user_id} - return self._pagination("/v1/user/illusts", params) + return self._pagination("/v1/user/illusts", params, user_data="user") def user_novels(self, user_id): params = {"user_id": user_id} @@ -1300,19 +1300,23 @@ class PixivAppAPI(): raise exception.AbortExtraction(f"API request failed: {error}") def _pagination(self, endpoint, params, - key_items="illusts", key_data=None): - while True: - data = self._call(endpoint, params) + key_items="illusts", key_data=None, user_data=None): + data = self._call(endpoint, params) - if key_data: - self.data = data.get(key_data) - key_data = None + if key_data is not None: + self.data = data.get(key_data) + if user_data is not None: + if not data[user_data].get("id"): + raise exception.NotFoundError("user") + + while True: yield from data[key_items] if not data["next_url"]: return query = data["next_url"].rpartition("?")[2] params = text.parse_query(query) + data = self._call(endpoint, params) @cache(maxage=36500*86400, keyarg=0) diff --git a/test/results/pixiv.py b/test/results/pixiv.py index ad6ac4b8..b50ce3c0 100644 --- a/test/results/pixiv.py +++ b/test/results/pixiv.py @@ -136,6 +136,7 @@ __tests__ = ( "#comment" : "deleted account with a different error", "#class" : pixiv.PixivArtworksExtractor, "#log" : "'User has left pixiv or the user ID does not exist.'", + "#exception": exception.NotFoundError, }, { @@ -175,6 +176,13 @@ __tests__ = ( "#class" : pixiv.PixivArtworksExtractor, }, +{ + "#url" : "https://www.pixiv.net/users/70060776/artworks", + "#comment" : "suspended account (#7990)", + "#class" : pixiv.PixivArtworksExtractor, + "#exception": exception.NotFoundError, +}, + { "#url" : "https://www.pixiv.net/en/users/173530/avatar", "#class" : pixiv.PixivAvatarExtractor,