Skip to content

Commit

Permalink
[batoto] raise exception if chapter is unavailable (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Sep 24, 2016
1 parent 2418bfe commit 0a3fb19
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions gallery_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions gallery_dl/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
13 changes: 11 additions & 2 deletions gallery_dl/extractor/batoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ def items(self):
"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()
Expand Down Expand Up @@ -119,7 +128,7 @@ def _login_impl(self, username, password):
"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")}

0 comments on commit 0a3fb19

Please sign in to comment.