use 'cookiedomain' for cookies set by object-config-values
otherwise these cookies would not be picked up by the _check_cookies() method.
This commit is contained in:
parent
00a23fe208
commit
808f67ba7d
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user