From 2be4c9ffe37ecfb1a357cb9374325dacaa19b4c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 16 Sep 2018 21:01:28 +0200 Subject: [PATCH] [sankaku] small code improvements --- gallery_dl/extractor/sankaku.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gallery_dl/extractor/sankaku.py b/gallery_dl/extractor/sankaku.py index e8b55396..e8d39261 100644 --- a/gallery_dl/extractor/sankaku.py +++ b/gallery_dl/extractor/sankaku.py @@ -130,14 +130,15 @@ class SankakuExtractor(SharedConfigExtractor): """Actual login implementation""" username = usertuple[0] self.log.info("Logging in as %s", username) + url = self.root + "/user/authenticate" data = { "url": "", "user[name]": username, "user[password]": password, "commit": "Login", } - response = self.request(self.root + "/user/authenticate", - method="POST", data=data) + response = self.request(url, method="POST", data=data) + if not response.history or response.url != self.root + "/user/home": raise exception.AuthenticationError() cookies = response.history[0].cookies @@ -225,12 +226,10 @@ class SankakuTagExtractor(SankakuExtractor): return yield from ids - next_url = text.extract(page, 'next-page-url="/?', '"', pos)[0] - if next_url: - params["next"] = text.parse_query(next_url)["next"] - else: - params["next"] = text.parse_int(ids[-1]) - 1 - params["page"] = 2 + next_qs = text.extract(page, 'next-page-url="/?', '"', pos)[0] + next_id = text.parse_query(next_qs).get("next") + params["next"] = next_id or (text.parse_int(ids[-1]) - 1) + params["page"] = "2" class SankakuPoolExtractor(SankakuExtractor):