diff --git a/gallery_dl/extractor/batoto.py b/gallery_dl/extractor/batoto.py index 88ad06a9..ea5f1824 100644 --- a/gallery_dl/extractor/batoto.py +++ b/gallery_dl/extractor/batoto.py @@ -20,17 +20,18 @@ class BatotoExtractor(): scheme = "https" root = "https://bato.to" cookienames = ("member_id", "pass_hash") + cookiedomain = ".bato.to" def login(self): """Login and set necessary cookies""" - if self._check_cookies(self.cookienames, ".bato.to"): + if self._check_cookies(self.cookienames): return username, password = self.auth_info() if username: cookies = self._login_impl(username, password) for key, value in cookies.items(): self.session.cookies.set( - key, value, domain=".bato.to", path="/") + key, value, domain=self.cookiedomain) @cache(maxage=7*24*60*60, keyarg=1) def _login_impl(self, username, password): diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 4926dbf9..0fa40ef0 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -26,6 +26,7 @@ class Extractor(): subcategory = "" directory_fmt = ["{category}"] filename_fmt = "{filename}" + cookiedomain = "" def __init__(self): self.session = requests.Session() @@ -34,14 +35,16 @@ class Extractor(): cookies = self.config("cookies") if cookies: if isinstance(cookies, dict): - cj = cookies + setcookie = self.session.cookies.set + for name, value in cookies.items(): + setcookie(name, value, domain=self.cookiedomain) else: try: cj = http.cookiejar.MozillaCookieJar() cj.load(cookies) + self.session.cookies.update(cj) except OSError as exc: self.log.warning("cookies: %s", exc) - self.session.cookies.update(cj) def __iter__(self): return self.items() @@ -82,6 +85,8 @@ class Extractor(): def _check_cookies(self, cookienames, domain=None): """Return True if all 'cookienames' exist in the current session""" + if not domain and self.cookiedomain: + domain = self.cookiedomain for name in cookienames: try: self.session.cookies._find(name, domain) diff --git a/gallery_dl/extractor/exhentai.py b/gallery_dl/extractor/exhentai.py index 30df13e8..2acfa6c5 100644 --- a/gallery_dl/extractor/exhentai.py +++ b/gallery_dl/extractor/exhentai.py @@ -37,6 +37,7 @@ class ExhentaiGalleryExtractor(Extractor): ] root = "https://exhentai.org" cookienames = ("ipb_member_id", "ipb_pass_hash") + cookiedomain = ".exhentai.org" def __init__(self, match): Extractor.__init__(self) @@ -177,7 +178,7 @@ class ExhentaiGalleryExtractor(Extractor): def login(self): """Login and set necessary cookies""" - if self._check_cookies(self.cookienames, ".exhentai.org"): + if self._check_cookies(self.cookienames): return username, password = self.auth_info() if not username: @@ -188,7 +189,7 @@ class ExhentaiGalleryExtractor(Extractor): cookies = self._login_impl(username, password) for key, value in cookies.items(): self.session.cookies.set( - key, value, domain=".exhentai.org", path="/") + key, value, domain=self.cookiedomain) @cache(maxage=90*24*60*60, keyarg=1) def _login_impl(self, username, password): diff --git a/gallery_dl/extractor/nijie.py b/gallery_dl/extractor/nijie.py index 7a59f0c0..b335e7fe 100644 --- a/gallery_dl/extractor/nijie.py +++ b/gallery_dl/extractor/nijie.py @@ -18,6 +18,7 @@ class NijieExtractor(AsynchronousExtractor): category = "nijie" directory_fmt = ["{category}", "{artist-id}"] filename_fmt = "{category}_{artist-id}_{image-id}_p{index:>02}.{extension}" + cookiedomain = "nijie.info" popup_url = "https://nijie.info/view_popup.php?id=" def __init__(self): @@ -62,7 +63,7 @@ class NijieExtractor(AsynchronousExtractor): def login(self): """Login and obtain session cookie""" - if self._check_cookies(("nemail", "nlogin"), "nijie.info"): + if self._check_cookies(("nemail", "nlogin")): return username, password = self.auth_info() self.session.cookies = self._login_impl(username, password) diff --git a/gallery_dl/extractor/seiga.py b/gallery_dl/extractor/seiga.py index adb65443..b005f16c 100644 --- a/gallery_dl/extractor/seiga.py +++ b/gallery_dl/extractor/seiga.py @@ -17,6 +17,7 @@ from xml.etree import ElementTree class SeigaExtractor(Extractor): """Base class for seiga extractors""" category = "seiga" + cookiedomain = ".nicovideo.jp" def items(self): self.login() @@ -47,7 +48,7 @@ class SeigaExtractor(Extractor): def login(self): """Login and set necessary cookies""" - if self._check_cookies(("user_session",), ".nicovideo.jp"): + if self._check_cookies(("user_session",)): return username, password = self.auth_info() self.session.cookies = self._login_impl(username, password)