Skip to content

Commit

Permalink
fix(OurBits): 应对OB站点Cookies会服务器过期问题
Browse files Browse the repository at this point in the history
因为直接使用requests.post,服务器响应是302 + Set-Cookies,所以直接使用r.cookies拿不到 ourbits_jwt,需要使用requests.Session() 才能通过s.cookies哪到 ourbits_jwt
  • Loading branch information
Rhilip committed Jan 6, 2020
1 parent e9527a8 commit 8cff03f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
7 changes: 6 additions & 1 deletion extractors/base/nexusphp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 12 additions & 1 deletion extractors/base/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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.....
Expand Down
16 changes: 16 additions & 0 deletions extractors/ourbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<name>.+?)\.torrent", torrent_page.text).group("name")
Expand Down

0 comments on commit 8cff03f

Please sign in to comment.