diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 45b815ec..6e5ae0a8 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -135,6 +135,9 @@ def main(): 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", diff --git a/gallery_dl/exception.py b/gallery_dl/exception.py index 0448aa7e..43e3d1e8 100644 --- a/gallery_dl/exception.py +++ b/gallery_dl/exception.py @@ -12,5 +12,8 @@ class NoExtractorError(Exception): class AuthenticationError(Exception): """Invalid or missing login information""" +class AuthorizationError(Exception): + """Insufficient privileges to access a resource""" + class NotFoundError(Exception): """Requested resource (gallery/image) does not exist""" diff --git a/gallery_dl/extractor/batoto.py b/gallery_dl/extractor/batoto.py index 0eb9bb54..56b92e39 100644 --- a/gallery_dl/extractor/batoto.py +++ b/gallery_dl/extractor/batoto.py @@ -42,7 +42,16 @@ class BatotoChapterExtractor(AsynchronousExtractor): "p": 1, "supress_webtoon": "t", } - page = self.request(self.reader_url, params=params).text + response = self.session.get(self.reader_url, params=params) + if response.status_code == 405: + error = text.extract(response.text, "ERROR [", "]")[0] + if error == "10030": + raise exception.AuthorizationError() + elif error == "10020": + raise exception.NotFoundError("chapter") + else: + raise Exception("[batoto] unexpected error code: " + error) + page = response.text data = self.get_job_metadata(page) yield Message.Version, 1 yield Message.Directory, data.copy() @@ -119,7 +128,7 @@ class BatotoChapterExtractor(AsynchronousExtractor): "anonymous": "1", } response = self.request(self.url + "forums/index.php", - method="POST", params=params, data=data) + method="POST", params=params, data=data) if "Sign In - " in response.text: raise exception.AuthenticationError() return {c: response.cookies[c] for c in ("member_id", "pass_hash")}