From 8cff03feba33e5389f322732c14610e04d7b50c6 Mon Sep 17 00:00:00 2001 From: Rhilip Date: Mon, 6 Jan 2020 14:41:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(OurBits):=20=E5=BA=94=E5=AF=B9OB=E7=AB=99?= =?UTF-8?q?=E7=82=B9Cookies=E4=BC=9A=E6=9C=8D=E5=8A=A1=E5=99=A8=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 因为直接使用requests.post,服务器响应是302 + Set-Cookies,所以直接使用r.cookies拿不到 ourbits_jwt,需要使用requests.Session() 才能通过s.cookies哪到 ourbits_jwt --- extractors/base/nexusphp.py | 7 ++++++- extractors/base/site.py | 13 ++++++++++++- extractors/ourbits.py | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/extractors/base/nexusphp.py b/extractors/base/nexusphp.py index 6783937..91bd9be 100644 --- a/extractors/base/nexusphp.py +++ b/extractors/base/nexusphp.py @@ -52,8 +52,13 @@ def session_check(self): self.status = True if page_usercp_bs.find(id="info_block") else False if self.status: Logger.debug("Through authentication in Site: {}".format(self.name)) - else: + elif self._AUTO_RENEW_COOKIES: + Logger.info('Update your cookies by login method in Site: {}'.format(self.name)) + self.update_cookies() + + if not self.status: Logger.error("Can not verify identity. Please Check your Cookies".format(mo=self.name)) + return self.status def torrent_link(self, tid): diff --git a/extractors/base/site.py b/extractors/base/site.py index 791ba71..e511805 100644 --- a/extractors/base/site.py +++ b/extractors/base/site.py @@ -24,6 +24,7 @@ class Site(object): encode = "bbcode" # bbcode or html suspended = 0 # 0 -> site Online, any number bigger than 0 -> Offline + config = {} def __init__(self, status: bool, cookies: dict or str, **kwargs): self.name = type(self).__name__ @@ -37,6 +38,7 @@ def __init__(self, status: bool, cookies: dict or str, **kwargs): self.status = False # -*- Assign Enhanced Features : Site -*- + self.config = kwargs """ Enhance Feature for `base` Reseeder. Those key-values will be set as default value unless you change it in your user-settings. @@ -56,6 +58,7 @@ def __init__(self, status: bool, cookies: dict or str, **kwargs): self._ASSIST_ONLY = kwargs.setdefault("assist_only", False) self._ASSIST_DELAY_TIME = kwargs.setdefault("assist_delay_time", 0) self._PASS_ONLINE_CHECK = kwargs.setdefault('pass_online_check', False) + self._AUTO_RENEW_COOKIES = kwargs.setdefault('auto_renew_cookies', False) # Check Site Online Status if self.status: @@ -81,9 +84,11 @@ def online_check(self) -> bool: self.suspended += 1 else: if self.suspended != 0: - Logger.info("The Site: {si} is Online now,after {count} times tries." + Logger.info("The Site: {si} is Online now, after {count} times tries." "Will check the session soon.".format(si=self.url_host, count=self.suspended)) self.suspended = 0 # Set self.suspended as 0 first, then session_check() + + if self.suspended == 0: self.session_check() return True if self.suspended == 0 else False @@ -194,6 +199,12 @@ def session_check(self): """ raise NotImplementedError + def update_cookies(self): + """ + Login function to update cookies + """ + raise NotImplementedError + def torrent_reseed(self, torrent): """ Main reseed function of Reseeder..... diff --git a/extractors/ourbits.py b/extractors/ourbits.py index 26072c0..d0693cb 100644 --- a/extractors/ourbits.py +++ b/extractors/ourbits.py @@ -15,6 +15,22 @@ class OurBits(NexusPHP): url_host = "https://ourbits.club" db_column = "ourbits.club" + def update_cookies(self): + username = self.config.get('username') + password = self.config.get('password') + + s = requests.Session() + r = s.post(self.url_host + '/takelogin.php', data={ + 'username': username, + 'password': password, + 'trackerssl': 'yes' + }) + if r.url.find('/index.php') > -1: + Logger.info('Update Cookies Successful.') + new_cookies = s.cookies['ourbits_jwt'] + self.cookies = {'ourbits_jwt': new_cookies} + self.status = True + def exist_torrent_title(self, tag): torrent_page = self.page_torrent_detail(tid=tag, bs=True) torrent_title = re.search("\[OurBits\]\.(?P.+?)\.torrent", torrent_page.text).group("name")