Browse Source

avoid endless waiting

master
imDMG 6 years ago
parent
commit
c2a0e49937
  1. 25
      kinozal.py
  2. 20
      nnmclub.py

25
kinozal.py

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
# VERSION: 1.1
# AUTHORS: imDMG (imdmgg@gmail.com)
# VERSION: 1.2
# AUTHORS: imDMG [imdmgg@gmail.com]
# Kinozal.tv search engine plugin for qBittorrent
@ -56,6 +56,9 @@ class kinozal(object): @@ -56,6 +56,9 @@ class kinozal(object):
cj = CookieJar()
self.session = build_opener(HTTPCookieProcessor(cj))
# avoid endless waiting
self.blocked = False
# add proxy handler if needed
if self.config['proxy'] and any(self.config['proxies'].keys()):
self.session.add_handler(ProxyHandler(self.config['proxies']))
@ -68,12 +71,8 @@ class kinozal(object): @@ -68,12 +71,8 @@ class kinozal(object):
# so we first encode keys to cp1251 then do default decode whole string
data_encoded = urlencode({k: v.encode('cp1251') for k, v in form_data.items()}).encode()
response = self._catch_error_request(self.url + '/takelogin.php', data_encoded)
# checking that tracker is'nt blocked
if self.url not in response.geturl():
logging.warning("{} is blocked. Try proxy or another proxy".format(self.url))
exit()
self._catch_error_request(self.url + '/takelogin.php', data_encoded)
if not self.blocked:
if 'uid' not in [cookie.name for cookie in cj]:
logging.warning("we not authorized, please check your credentials")
else:
@ -188,6 +187,8 @@ class kinozal(object): @@ -188,6 +187,8 @@ class kinozal(object):
pass
def download_torrent(self, url):
if self.blocked:
return
# Create a torrent file
file, path = tempfile.mkstemp('.torrent')
file = os.fdopen(file, "wb")
@ -204,6 +205,8 @@ class kinozal(object): @@ -204,6 +205,8 @@ class kinozal(object):
print(path + " " + url)
def search(self, what, cat='all'):
if self.blocked:
return
query = '{}/browse.php?s={}&c={}'.format(self.url, what.replace(" ", "+"), self.supported_categories[cat])
response = self._catch_error_request(query)
parser = self.WorstParser(self.url)
@ -235,6 +238,12 @@ class kinozal(object): @@ -235,6 +238,12 @@ class kinozal(object):
logging.error(e)
raise e
# checking that tracker is'nt blocked
self.blocked = False
if self.url not in response.geturl():
logging.warning("{} is blocked. Try proxy or another proxy".format(self.url))
self.blocked = True
return response

20
nnmclub.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
# VERSION: 1.1
# VERSION: 1.2
# AUTHORS: imDMG [imdmgg@gmail.com]
# NoNaMe-Club search engine plugin for qBittorrent
@ -60,6 +60,9 @@ class nnmclub(object): @@ -60,6 +60,9 @@ class nnmclub(object):
cj.set_cookie(c)
self.session = build_opener(HTTPCookieProcessor(cj))
# avoid endless waiting
self.blocked = False
# add proxy handler if needed
if self.config['proxy'] and any(self.config['proxies'].keys()):
self.session.add_handler(ProxyHandler(self.config['proxies']))
@ -69,10 +72,7 @@ class nnmclub(object): @@ -69,10 +72,7 @@ class nnmclub(object):
self.session.addheaders.append(('User-Agent', self.config['ua']))
response = self._catch_error_request(self.url + 'login.php')
# checking that tracker is'nt blocked
if self.url not in response.geturl():
logging.warning("{} is blocked. Try proxy or another proxy".format(self.url))
exit()
if not self.blocked:
parser = self.WorstParser(self.url, True)
parser.feed(response.read().decode('cp1251'))
parser.close()
@ -210,6 +210,8 @@ class nnmclub(object): @@ -210,6 +210,8 @@ class nnmclub(object):
pass
def download_torrent(self, url):
if self.blocked:
return
# Create a torrent file
file, path = tempfile.mkstemp('.torrent')
file = os.fdopen(file, "wb")
@ -226,6 +228,8 @@ class nnmclub(object): @@ -226,6 +228,8 @@ class nnmclub(object):
print(path + " " + url)
def search(self, what, cat='all'):
if self.blocked:
return
c = self.supported_categories[cat]
query = '{}tracker.php?nm={}&{}'.format(self.url, what.replace(" ", "+"), "f=-1" if c == '-1' else "c=" + c)
response = self._catch_error_request(query)
@ -260,6 +264,12 @@ class nnmclub(object): @@ -260,6 +264,12 @@ class nnmclub(object):
logging.error(e)
raise e
# checking that tracker is'nt blocked
self.blocked = False
if self.url not in response.geturl():
logging.warning("{} is blocked. Try proxy or another proxy".format(self.url))
self.blocked = True
return response

Loading…
Cancel
Save