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