From d9b94a585d50fa41361511364e355a154ed5c88c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 9 Apr 2019 16:54:15 +0200 Subject: [PATCH] [mangoxo] add login support (#184) A very recent change: It is now only possible to see more than the first 5 images of an album if you are logged in. --- docs/supportedsites.rst | 2 +- gallery_dl/extractor/mangoxo.py | 36 ++++++++++++++++++++++++++++++++- scripts/supportedsites.py | 1 + test/test_results.py | 1 + 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/supportedsites.rst b/docs/supportedsites.rst index 86a86d05ddb..f6ed52dbb06 100644 --- a/docs/supportedsites.rst +++ b/docs/supportedsites.rst @@ -61,7 +61,7 @@ MangaDex https://mangadex.org/ Chapters, Manga Mangapanda https://www.mangapanda.com/ Chapters, Manga MangaPark https://mangapark.me/ Chapters, Manga Mangareader https://www.mangareader.net/ Chapters, Manga -Mangoxo https://www.mangoxo.com/ Albums, Channels +Mangoxo https://www.mangoxo.com/ Albums, Channels Optional Newgrounds https://www.newgrounds.com/ Images from Users, individual Images, Videos Ngomik http://ngomik.in/ Chapters nhentai https://nhentai.net/ Galleries, Search Results diff --git a/gallery_dl/extractor/mangoxo.py b/gallery_dl/extractor/mangoxo.py index 7e7037b2ba3..3e431aec1c9 100644 --- a/gallery_dl/extractor/mangoxo.py +++ b/gallery_dl/extractor/mangoxo.py @@ -9,13 +9,45 @@ """Extractors for https://www.mangoxo.com/""" from .common import Extractor, Message -from .. import text +from .. import text, exception +from ..cache import cache class MangoxoBase(): """Base class for mangoxo extractors""" category = "mangoxo" root = "https://www.mangoxo.com" + cookiedomain = "www.mangoxo.com" + cookienames = ("SESSION",) + _warning = True + + def login(self): + username, password = self._get_auth_info() + if username: + self._update_cookies(self._login_impl(username, password)) + elif MangoxoBase._warning: + MangoxoBase._warning = False + self.log.warning("Unauthenticated users cannot see " + "more than 5 images per album") + + @cache(maxage=3*3600, keyarg=1) + def _login_impl(self, username, password): + self.log.info("Logging in as %s", username) + + url = self.root + "/login/loginxmm" + headers = { + "X-Requested-With": "XMLHttpRequest", + "Referer": self.root + "/login", + } + data = { + "name": username, + "password": password, + } + response = self.request(url, method="POST", headers=headers, data=data) + session = response.cookies.get("SESSION") + if not session: + raise exception.AuthenticationError() + return {"SESSION": session} @staticmethod def _total_pages(page): @@ -53,6 +85,7 @@ def __init__(self, match): self.album_id = match.group(1) def items(self): + self.login() url = "{}/album/{}/".format(self.root, self.album_id) page = self.request(url).text data = self.metadata(page) @@ -117,6 +150,7 @@ def __init__(self, match): self.channel_id = match.group(1) def items(self): + self.login() yield Message.Version, 1 url = "{}/channel/{}/".format(self.root, self.channel_id) num = total = 1 diff --git a/scripts/supportedsites.py b/scripts/supportedsites.py index c975be29525..c032154fcc9 100755 --- a/scripts/supportedsites.py +++ b/scripts/supportedsites.py @@ -102,6 +102,7 @@ "flickr" : "Optional (OAuth)", "idolcomplex": "Optional", "luscious" : "Optional", + "mangoxo" : "Optional", "nijie" : "Required", "pixiv" : "Required", "reddit" : "Optional (OAuth)", diff --git a/test/test_results.py b/test/test_results.py index a7df5021d9b..1af5b9701e6 100644 --- a/test/test_results.py +++ b/test/test_results.py @@ -228,6 +228,7 @@ def setup_test_config(): config.set(("extractor", "seiga", "username"), email) config.set(("extractor", "danbooru", "username"), None) config.set(("extractor", "twitter" , "username"), None) + config.set(("extractor", "mangoxo" , "password"), "VZ8DL3983u") config.set(("extractor", "deviantart", "client-id"), "7777") config.set(("extractor", "deviantart", "client-secret"),