[pixiv] detect suspended/deleted accounts (#7990)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user