[exhentai] update login procedure (#37)

This new version behaves pretty much exactly like a browser would and
caches all cookies sent to it and not just "ipb_member_id" and
"ipb_pass_hash".
pull/40/head
Mike Fährmann 7 years ago
parent 88a386977e
commit 3ee39ffd93
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -61,12 +61,11 @@ class ExhentaiGalleryExtractor(Extractor):
url = "{}/g/{}/{}/".format(self.root, self.gid, self.token) url = "{}/g/{}/{}/".format(self.root, self.gid, self.token)
response = self.request(url, fatal=False) response = self.request(url, fatal=False)
page, headers = response.text, response.headers page = response.text
if response.status_code == 404 and "Gallery Not Available" in page: if response.status_code == 404 and "Gallery Not Available" in page:
raise exception.AuthorizationError() raise exception.AuthorizationError()
if (headers.get("Content-Length") == "9615" and if self._is_sadpanda(response):
"sadpanda.jpg" in headers.get("Content-Disposition", "")):
self.log.info("sadpanda.jpg") self.log.info("sadpanda.jpg")
raise exception.AuthorizationError() raise exception.AuthorizationError()
if page.startswith(("Key missing", "Gallery not found")): if page.startswith(("Key missing", "Gallery not found")):
@ -80,7 +79,7 @@ class ExhentaiGalleryExtractor(Extractor):
data.update(image) data.update(image)
if "/fullimg.php" in url: if "/fullimg.php" in url:
data["extension"] = "" data["extension"] = ""
self.wait((1, 2)) self.wait(1.5)
yield Message.Url, url, data yield Message.Url, url, data
def get_job_metadata(self, page): def get_job_metadata(self, page):
@ -175,7 +174,7 @@ class ExhentaiGalleryExtractor(Extractor):
if not waittime: if not waittime:
waittime = random.uniform(self.wait_min, self.wait_max) waittime = random.uniform(self.wait_min, self.wait_max)
else: else:
waittime = random.uniform(*waittime) waittime = random.uniform(waittime * 0.66, waittime * 1.33)
time.sleep(waittime) time.sleep(waittime)
def login(self): def login(self):
@ -197,6 +196,11 @@ class ExhentaiGalleryExtractor(Extractor):
def _login_impl(self, username, password): def _login_impl(self, username, password):
"""Actual login implementation""" """Actual login implementation"""
self.log.info("Logging in as %s", username) self.log.info("Logging in as %s", username)
# visit "home.php" to get "__cfduid" cookie
response = self.request("https://e-hentai.org/home.php")
# send login form
url = "https://forums.e-hentai.org/index.php?act=Login&CODE=01" url = "https://forums.e-hentai.org/index.php?act=Login&CODE=01"
data = { data = {
"CookieDate": "1", "CookieDate": "1",
@ -207,11 +211,30 @@ class ExhentaiGalleryExtractor(Extractor):
"ipb_login_submit": "Login!", "ipb_login_submit": "Login!",
} }
headers = { headers = {
"Referer": "https://e-hentai.org/bounce_login.php?b=d&bt=1-1" "Referer": response.url
} }
response = self.request(url, method="POST", data=data, headers=headers) response = self.request(url, method="POST", data=data, headers=headers)
if "You are now logged in as:" not in response.text: # visit "exhentai.org" to transfer cookies
self.log.debug(response.text) self.wait(1.5)
response = self.request("https://exhentai.org")
if self._is_sadpanda(response):
raise exception.AuthenticationError() raise exception.AuthenticationError()
return {c: response.cookies[c] for c in self.cookienames}
# collect exhentai cookies in dict (this should yield
# "ipb_member_id", "ipb_pass_hash", "igneous", and "yay")
cookies = {
c.name: c.value
for c in self.session.cookies
if c.domain == self.cookiedomain
}
return cookies
@staticmethod
def _is_sadpanda(response):
"""Return True if the response object contains a sad panda"""
return (
response.headers.get("Content-Length") == "9615" and
"sadpanda.jpg" in response.headers.get("Content-Disposition", "")
)

@ -63,6 +63,9 @@ skip = [
"exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie", "exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie",
"archivedmoe", "archiveofsins", "thebarchive", "archivedmoe", "archiveofsins", "thebarchive",
# temporary issues # temporary issues
"jaiminisbox", # 522
"e621",
"3dbooru",
] ]
# enable selective testing for direct calls # enable selective testing for direct calls
if __name__ == '__main__' and len(sys.argv) > 1: if __name__ == '__main__' and len(sys.argv) > 1:

Loading…
Cancel
Save