diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 88035250..506ee54c 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -87,6 +87,12 @@ def main(): else: jobtype = job.DownloadJob for url in args.urls: - jobtype(url).run() + try: + jobtype(url).run() + except exception.NoExtractorError: + print("No suitable extractor found for URL '", url, "'", sep="") + except exception.AuthenticationError: + print("Authentication failed. Please provide a valid " + "username/password pair.") except KeyboardInterrupt: print("\nKeyboardInterrupt") diff --git a/gallery_dl/exception.py b/gallery_dl/exception.py index a0d467cb..84c5ed9c 100644 --- a/gallery_dl/exception.py +++ b/gallery_dl/exception.py @@ -8,3 +8,6 @@ class NoExtractorError(Exception): pass + +class AuthenticationError(Exception): + pass diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index 43b58053..bae48c65 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -9,7 +9,7 @@ """Extract images and ugoira from http://www.pixiv.net/""" from .common import Extractor, Message -from .. import config, text +from .. import config, text, exception from ..cache import cache import re import json @@ -213,8 +213,8 @@ class PixivAPI(): def login(self): """Login and gain a Pixiv Public-API access token""" - self.user_id, token = self._do_login(self.username, self.password) - self.session.headers["Authorization"] = "Bearer " + token + self.user_id, auth_header = self._do_login(self.username, self.password) + self.session.headers["Authorization"] = auth_header @require_login def user(self, user_id): @@ -280,15 +280,14 @@ class PixivAPI(): "https://oauth.secure.pixiv.net/auth/token", data=data ) if response.status_code not in (200, 301, 302): - raise Exception("login() failed! check username and password.\n" - "HTTP %s: %s" % (response.status_code, response.text)) + raise exception.AuthenticationError() try: response = self._parse(response)["response"] token = response["access_token"] user = response["user"]["id"] except: raise Exception("Get access_token error! Response: %s" % (token)) - return user, token + return user, "Bearer " + token @staticmethod def _parse(response):