[batoto] raise exception if chapter is unavailable (#4)
This commit is contained in:
@@ -135,6 +135,9 @@ def main():
|
|||||||
except exception.AuthenticationError:
|
except exception.AuthenticationError:
|
||||||
print("Authentication failed. Please provide a valid "
|
print("Authentication failed. Please provide a valid "
|
||||||
"username/password pair.", file=sys.stderr)
|
"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:
|
except exception.NotFoundError as err:
|
||||||
res = str(err) or "resource (gallery/image/user)"
|
res = str(err) or "resource (gallery/image/user)"
|
||||||
print("The ", res, " at '", url, "' does not exist",
|
print("The ", res, " at '", url, "' does not exist",
|
||||||
|
|||||||
@@ -12,5 +12,8 @@ class NoExtractorError(Exception):
|
|||||||
class AuthenticationError(Exception):
|
class AuthenticationError(Exception):
|
||||||
"""Invalid or missing login information"""
|
"""Invalid or missing login information"""
|
||||||
|
|
||||||
|
class AuthorizationError(Exception):
|
||||||
|
"""Insufficient privileges to access a resource"""
|
||||||
|
|
||||||
class NotFoundError(Exception):
|
class NotFoundError(Exception):
|
||||||
"""Requested resource (gallery/image) does not exist"""
|
"""Requested resource (gallery/image) does not exist"""
|
||||||
|
|||||||
@@ -42,7 +42,16 @@ class BatotoChapterExtractor(AsynchronousExtractor):
|
|||||||
"p": 1,
|
"p": 1,
|
||||||
"supress_webtoon": "t",
|
"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)
|
data = self.get_job_metadata(page)
|
||||||
yield Message.Version, 1
|
yield Message.Version, 1
|
||||||
yield Message.Directory, data.copy()
|
yield Message.Directory, data.copy()
|
||||||
@@ -119,7 +128,7 @@ class BatotoChapterExtractor(AsynchronousExtractor):
|
|||||||
"anonymous": "1",
|
"anonymous": "1",
|
||||||
}
|
}
|
||||||
response = self.request(self.url + "forums/index.php",
|
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:
|
if "Sign In - " in response.text:
|
||||||
raise exception.AuthenticationError()
|
raise exception.AuthenticationError()
|
||||||
return {c: response.cookies[c] for c in ("member_id", "pass_hash")}
|
return {c: response.cookies[c] for c in ("member_id", "pass_hash")}
|
||||||
|
|||||||
Reference in New Issue
Block a user