Browse Source

v2.4 added relogin if session isnt alive

master
imDMG 4 years ago
parent
commit
54d1a44534
  1. 21
      nnmclub.py

21
nnmclub.py

@ -1,4 +1,4 @@
# VERSION: 2.3 # VERSION: 2.4
# AUTHORS: imDMG [imdmgg@gmail.com] # AUTHORS: imDMG [imdmgg@gmail.com]
# NoNaMe-Club search engine plugin for qBittorrent # NoNaMe-Club search engine plugin for qBittorrent
@ -11,8 +11,8 @@ import re
import socket import socket
import tempfile import tempfile
import time import time
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from html import unescape
from http.cookiejar import Cookie, MozillaCookieJar from http.cookiejar import Cookie, MozillaCookieJar
from urllib.error import URLError, HTTPError from urllib.error import URLError, HTTPError
from urllib.parse import urlencode, unquote from urllib.parse import urlencode, unquote
@ -140,8 +140,8 @@ class nnmclub:
mcj = MozillaCookieJar() mcj = MozillaCookieJar()
try: try:
mcj.load(FILE_C, ignore_discard=True) mcj.load(FILE_C, ignore_discard=True)
if 'phpbb2mysql_4_sid' in [cookie.name for cookie in mcj]: key = 'phpbb2mysql_4_data'
# if cookie.expires < int(time.time()) if [True for c in mcj if c.name == key and c.expires > time.time()]:
logger.info("Local cookies is loaded") logger.info("Local cookies is loaded")
self.session.add_handler(HTTPCookieProcessor(mcj)) self.session.add_handler(HTTPCookieProcessor(mcj))
else: else:
@ -195,9 +195,9 @@ class nnmclub:
if self.error: if self.error:
return return
# if we wanna use https we mast add ssl=enable_ssl to cookie # if we wanna use https we mast add ssl=enable_ssl to cookie
mcj.set_cookie(Cookie(0, 'ssl', "enable_ssl", None, False, mcj.set_cookie(Cookie(0, "ssl", "enable_ssl", None, False,
'.nnmclub.to', True, False, '/', True, ".nnmclub.to", True, False, "/", True,
False, None, 'ParserCookie', None, None, None)) False, None, False, None, None, {}))
self.session.add_handler(HTTPCookieProcessor(mcj)) self.session.add_handler(HTTPCookieProcessor(mcj))
response = self._catch_error_request(self.url + 'login.php') response = self._catch_error_request(self.url + 'login.php')
@ -236,7 +236,7 @@ class nnmclub:
prettyPrinter({ prettyPrinter({
"engine_url": self.url, "engine_url": self.url,
"desc_link": self.url + tor[0], "desc_link": self.url + tor[0],
"name": torrent_date + tor[1], "name": torrent_date + unescape(tor[1]),
"link": self.url + tor[2], "link": self.url + tor[2],
"size": tor[3].replace(',', '.'), "size": tor[3].replace(',', '.'),
"seeds": tor[4], "seeds": tor[4],
@ -249,6 +249,11 @@ class nnmclub:
if not response: if not response:
return None return None
page = response.read().decode('cp1251') page = response.read().decode('cp1251')
if first and page.find(f'Выход [ {config["username"]} ]') == -1:
logger.debug("Looks like we lost session id, lets login")
self.login(MozillaCookieJar())
if self.error:
return None
self.draw(page) self.draw(page)
return int(re.search(PATTERNS[0], page)[1]) if first else -1 return int(re.search(PATTERNS[0], page)[1]) if first else -1

Loading…
Cancel
Save