From effa1084f2e53154266e0b00acbc4d543003d7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 28 Aug 2016 16:21:51 +0200 Subject: [PATCH] [pixiv] raise NotFoundError instead of failing --- gallery_dl/__init__.py | 8 ++++++-- gallery_dl/extractor/pixiv.py | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 7e8b581c..a1fc5465 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -123,12 +123,16 @@ def main(): except exception.AuthenticationError: print("Authentication failed. Please provide a valid " "username/password pair.", file=sys.stderr) + except exception.NotFoundError as err: + res = str(err) or "resource (gallery/image/user)" + print("The ", res, " at '", url, "' does not exist", + sep="", file=sys.stderr) except KeyboardInterrupt: print("\nKeyboardInterrupt", file=sys.stderr) except BrokenPipeError: pass - except IOError as e: + except IOError as err: import errno - if e.errno != errno.EPIPE: + if err.errno != errno.EPIPE: raise diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index fc554216..a25a8290 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -303,6 +303,9 @@ class PixivAPI(): return user, "Bearer " + token @staticmethod - def _parse(response): + def _parse(response, empty=[None]): """Parse a Pixiv Public-API response""" - return json.loads(response.text) + data = json.loads(response.text) + if data["status"] == "failure" or data["response"] == empty: + raise exception.NotFoundError() + return data