aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/exception.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/exception.py')
-rw-r--r--gallery_dl/exception.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/gallery_dl/exception.py b/gallery_dl/exception.py
index 5a52581..6adda0d 100644
--- a/gallery_dl/exception.py
+++ b/gallery_dl/exception.py
@@ -100,12 +100,17 @@ class AuthorizationError(ExtractionError):
class AuthRequired(AuthorizationError):
default = "Account credentials required"
- def __init__(self, required=None, message=None):
- if required and not message:
- if isinstance(required, str):
- message = f"{required} required"
+ def __init__(self, auth=None, resource="resource", message=None):
+ if auth:
+ if not isinstance(auth, str):
+ auth = " or ".join(auth)
+ if " " not in resource:
+ resource = "this " + resource
+ if message is None:
+ message = (f"{auth} needed to access {resource}")
else:
- message = f"{' or '.join(required)} required"
+ message = (f"{auth} needed to access {resource} "
+ f"('{message}')")
AuthorizationError.__init__(self, message)
@@ -160,6 +165,22 @@ class ControlException(GalleryDLException):
class StopExtraction(ControlException):
"""Stop data extraction"""
+ def __init__(self, target=None):
+ ControlException.__init__(self)
+
+ if target is None:
+ self.target = None
+ self.depth = 1
+ elif isinstance(target, int):
+ self.target = None
+ self.depth = target
+ elif target.isdecimal():
+ self.target = None
+ self.depth = int(target)
+ else:
+ self.target = target
+ self.depth = 128
+
class AbortExtraction(ExtractionError, ControlException):
"""Abort data extraction due to an error"""