From 4a8d74973c535e3ba74a41bc5aa88596320c40a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 8 Jan 2017 17:33:25 +0100 Subject: [PATCH] adjust login methods to a specific style --- gallery_dl/extractor/exhentai.py | 12 +++++++----- gallery_dl/extractor/nijie.py | 15 +++++++++------ gallery_dl/extractor/pixiv.py | 16 ++++++++-------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/gallery_dl/extractor/exhentai.py b/gallery_dl/extractor/exhentai.py index 94a44979..0561d6e2 100644 --- a/gallery_dl/extractor/exhentai.py +++ b/gallery_dl/extractor/exhentai.py @@ -169,12 +169,14 @@ class ExhentaiGalleryExtractor(Extractor): def login(self): """Login and set necessary cookies""" - cookies = self._login_impl() + username = config.interpolate(("extractor", "exhentai", "username")) + password = config.interpolate(("extractor", "exhentai", "password")) + cookies = self._login_impl(username, password) for key, value in cookies.items(): self.session.cookies.set(key, value, domain=".exhentai.org", path="/") - @cache(maxage=360*24*60*60) - def _login_impl(self): + @cache(maxage=360*24*60*60, keyarg=1) + def _login_impl(self, username, password): """Actual login implementation""" cnames = ["ipb_member_id", "ipb_pass_hash"] @@ -190,8 +192,8 @@ class ExhentaiGalleryExtractor(Extractor): "CookieDate": "1", "b": "d", "bt": "1-1", - "UserName": config.interpolate(("extractor", "exhentai", "username")), - "PassWord": config.interpolate(("extractor", "exhentai", "password")), + "UserName": username, + "PassWord": password, "ipb_login_submit": "Login!", } self.session.headers["Referer"] = "http://e-hentai.org/bounce_login.php?b=d&bt=1-1" diff --git a/gallery_dl/extractor/nijie.py b/gallery_dl/extractor/nijie.py index bee431a0..3b04bc2d 100644 --- a/gallery_dl/extractor/nijie.py +++ b/gallery_dl/extractor/nijie.py @@ -25,10 +25,7 @@ class NijieExtractor(AsynchronousExtractor): self.artist_id = "" def items(self): - self.session.cookies = self.login( - config.interpolate(("extractor", self.category, "username")), - config.interpolate(("extractor", self.category, "password")) - ) + self.login() data = self.get_job_metadata() images = self.get_image_ids() yield Message.Version, 1 @@ -62,9 +59,15 @@ class NijieExtractor(AsynchronousExtractor): "image-id": image_id, }) - @cache(maxage=30*24*60*60, keyarg=1) - def login(self, username, password): + def login(self): """Login and obtain session cookie""" + username = config.interpolate(("extractor", "nijie", "username")) + password = config.interpolate(("extractor", "nijie", "password")) + self.session.cookies = self._login_impl(username, password) + + @cache(maxage=30*24*60*60, keyarg=1) + def _login_impl(self, username, password): + """Actual login implementation""" params = {"email": username, "password": password} page = self.session.post("https://nijie.info/login_int.php", data=params).text diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index 00c14737..48458094 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -226,14 +226,7 @@ class PixivAPI(): "Referer": "http://www.pixiv.net/", "User-Agent": "PixivIOSApp/5.8.0", }) - self.user_id = -1 - self.username = config.interpolate(("extractor", "pixiv", "username")) - self.password = config.interpolate(("extractor", "pixiv", "password")) - - def login(self): - """Login and gain a Pixiv Public-API access token""" - self.user_id, auth_header = self._login_impl(self.username, self.password) - self.session.headers["Authorization"] = auth_header + self.user_id = -1 @require_login def user(self, user_id): @@ -285,6 +278,13 @@ class PixivAPI(): ) return self._parse(response) + def login(self): + """Login and gain a Pixiv Public-API access token""" + username = config.interpolate(("extractor", "pixiv", "username")) + password = config.interpolate(("extractor", "pixiv", "password")) + self.user_id, auth_header = self._login_impl(username, password) + self.session.headers["Authorization"] = auth_header + @cache(maxage=50*60, keyarg=1) def _login_impl(self, username, password): """Actual login implementation"""