From 24f41e13b3a6f5ebad7459a5fa3c36b1a0bab6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 25 Feb 2017 23:53:31 +0100 Subject: [PATCH] move some exception handling code --- gallery_dl/__init__.py | 11 +---------- gallery_dl/job.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 8e9a5d4b..6d45742d 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -182,16 +182,7 @@ def main(): except exception.NoExtractorError: print("No suitable extractor found for URL '", url, "'", sep="", file=sys.stderr) - except exception.AuthenticationError: - print("Authentication failed. Please provide a valid " - "username/password pair.", file=sys.stderr) - except exception.AuthorizationError: - print("You do not have permission to access the resource ", - "at '", url, "'", sep="", 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) diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 02e6ccb8..08cc4a12 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -6,6 +6,7 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. +import sys import json import hashlib from . import extractor, downloader, config, util, path, output, exception @@ -16,6 +17,7 @@ class Job(): """Base class for Job-types""" def __init__(self, url): + self.url = url self.extractor = extractor.find(url) if self.extractor is None: raise exception.NoExtractorError(url) @@ -53,6 +55,16 @@ class Job(): self.extractor.category, msg[1] ) # TODO: support for multiple message versions + except exception.AuthenticationError: + print("Authentication failed. Please provide a valid " + "username/password pair.", file=sys.stderr) + except exception.AuthorizationError: + print("You do not have permission to access the resource ", + "at '", self.url, "'", sep="", file=sys.stderr) + except exception.NotFoundError as err: + res = str(err) or "resource (gallery/image/user)" + print("The ", res, " at '", self.url, "' does not exist", + sep="", file=sys.stderr) except exception.StopExtraction: pass