Skip to content

Commit

Permalink
[mangoxo] fix login
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Mar 8, 2020
1 parent ebc70e8 commit a63a376
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gallery_dl/extractor/hentainexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class HentainexusGalleryExtractor(GalleryExtractor):
test = (
("https://hentainexus.com/view/5688", {
"url": "746d0043e20030f1171aae5ea113176607302517",
"keyword": "c1b7091e2bc2f733f6401711e072ad11cf93dd69",
"keyword": "77702b42f8f76ecfe5d8a14cfbbcbd855eb14d7f",
}),
("https://hentainexus.com/read/5688"),
)
Expand Down
35 changes: 21 additions & 14 deletions gallery_dl/extractor/mangoxo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2019 Mike Fährmann
# Copyright 2019-2020 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
Expand All @@ -12,6 +12,7 @@
from .. import text, exception
from ..cache import cache
import hashlib
import time


class MangoxoExtractor(Extractor):
Expand All @@ -35,27 +36,33 @@ def login(self):
def _login_impl(self, username, password):
self.log.info("Logging in as %s", username)

page = self.request(self.root + "/login/").text
token = text.extract(page, 'id="loginToken" value="', '"')[0]
if not token:
self.log.debug("failed to extract 'loginToken'")

url = self.root + "/login/loginxmm"
url = self.root + "/api/login"
headers = {
"X-Requested-With": "XMLHttpRequest",
"Referer": self.root + "/login",
}
data = {
"name": username,
"password": hashlib.md5(password.encode()).hexdigest(),
"loginToken": token,
}
data = self._sign_by_md5(username, password)
response = self.request(url, method="POST", headers=headers, data=data)

if response.json().get("result") != "1":
raise exception.AuthenticationError()
data = response.json()
if str(data.get("result")) != "1":
raise exception.AuthenticationError(data.get("msg"))
return {"SESSION": self.session.cookies.get("SESSION")}

@staticmethod
def _sign_by_md5(username, password):
# https://dns.mangoxo.com/libs/plugins/phoenix-ui/js/phoenix-ui.js
params = [
("username" , username),
("password" , password),
("timestamp", str(int(time.time()))),
]
query = "&".join("=".join(item) for item in sorted(params))
query += "&secretKey=996293536"
sign = hashlib.md5(query.encode()).hexdigest()
params.append(("sign", sign.upper()))
return params

@staticmethod
def _total_pages(page):
return text.parse_int(text.extract(page, "total :", ",")[0])
Expand Down
3 changes: 0 additions & 3 deletions test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
# temporary issues, etc.
BROKEN = {
"35photo",
"dokireader",
"furaffinity",
"mangapark",
"mangoxo",
"photobucket",
}

Expand Down

0 comments on commit a63a376

Please sign in to comment.