|
|
@ -1,4 +1,4 @@ |
|
|
|
# VERSION: 1.1 |
|
|
|
# VERSION: 1.2 |
|
|
|
# AUTHORS: imDMG [imdmgg@gmail.com] |
|
|
|
# AUTHORS: imDMG [imdmgg@gmail.com] |
|
|
|
|
|
|
|
|
|
|
|
# NoNaMe-Club search engine plugin for qBittorrent |
|
|
|
# NoNaMe-Club search engine plugin for qBittorrent |
|
|
@ -60,6 +60,9 @@ class nnmclub(object): |
|
|
|
cj.set_cookie(c) |
|
|
|
cj.set_cookie(c) |
|
|
|
self.session = build_opener(HTTPCookieProcessor(cj)) |
|
|
|
self.session = build_opener(HTTPCookieProcessor(cj)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# avoid endless waiting |
|
|
|
|
|
|
|
self.blocked = False |
|
|
|
|
|
|
|
|
|
|
|
# add proxy handler if needed |
|
|
|
# add proxy handler if needed |
|
|
|
if self.config['proxy'] and any(self.config['proxies'].keys()): |
|
|
|
if self.config['proxy'] and any(self.config['proxies'].keys()): |
|
|
|
self.session.add_handler(ProxyHandler(self.config['proxies'])) |
|
|
|
self.session.add_handler(ProxyHandler(self.config['proxies'])) |
|
|
@ -69,28 +72,25 @@ class nnmclub(object): |
|
|
|
self.session.addheaders.append(('User-Agent', self.config['ua'])) |
|
|
|
self.session.addheaders.append(('User-Agent', self.config['ua'])) |
|
|
|
|
|
|
|
|
|
|
|
response = self._catch_error_request(self.url + 'login.php') |
|
|
|
response = self._catch_error_request(self.url + 'login.php') |
|
|
|
# checking that tracker is'nt blocked |
|
|
|
if not self.blocked: |
|
|
|
if self.url not in response.geturl(): |
|
|
|
parser = self.WorstParser(self.url, True) |
|
|
|
logging.warning("{} is blocked. Try proxy or another proxy".format(self.url)) |
|
|
|
parser.feed(response.read().decode('cp1251')) |
|
|
|
exit() |
|
|
|
parser.close() |
|
|
|
parser = self.WorstParser(self.url, True) |
|
|
|
|
|
|
|
parser.feed(response.read().decode('cp1251')) |
|
|
|
form_data = {"username": self.config['username'], |
|
|
|
parser.close() |
|
|
|
"password": self.config['password'], |
|
|
|
|
|
|
|
"autologin": "on", |
|
|
|
form_data = {"username": self.config['username'], |
|
|
|
"code": parser.login_code, |
|
|
|
"password": self.config['password'], |
|
|
|
"login": "Вход"} |
|
|
|
"autologin": "on", |
|
|
|
# so we first encode keys to cp1251 then do default decode whole string |
|
|
|
"code": parser.login_code, |
|
|
|
data_encoded = urlencode({k: v.encode('cp1251') for k, v in form_data.items()}).encode() |
|
|
|
"login": "Вход"} |
|
|
|
|
|
|
|
# so we first encode keys to cp1251 then do default decode whole string |
|
|
|
self._catch_error_request(self.url + 'login.php', data_encoded) |
|
|
|
data_encoded = urlencode({k: v.encode('cp1251') for k, v in form_data.items()}).encode() |
|
|
|
|
|
|
|
|
|
|
|
if 'phpbb2mysql_4_sid' not in [cookie.name for cookie in cj]: |
|
|
|
self._catch_error_request(self.url + 'login.php', data_encoded) |
|
|
|
logging.warning("we not authorized, please check your credentials") |
|
|
|
|
|
|
|
else: |
|
|
|
if 'phpbb2mysql_4_sid' not in [cookie.name for cookie in cj]: |
|
|
|
logging.info('We successfully authorized') |
|
|
|
logging.warning("we not authorized, please check your credentials") |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
logging.info('We successfully authorized') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorstParser(HTMLParser): |
|
|
|
class WorstParser(HTMLParser): |
|
|
|
def __init__(self, url='', login=False): |
|
|
|
def __init__(self, url='', login=False): |
|
|
@ -210,6 +210,8 @@ class nnmclub(object): |
|
|
|
pass |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
def download_torrent(self, url): |
|
|
|
def download_torrent(self, url): |
|
|
|
|
|
|
|
if self.blocked: |
|
|
|
|
|
|
|
return |
|
|
|
# Create a torrent file |
|
|
|
# Create a torrent file |
|
|
|
file, path = tempfile.mkstemp('.torrent') |
|
|
|
file, path = tempfile.mkstemp('.torrent') |
|
|
|
file = os.fdopen(file, "wb") |
|
|
|
file = os.fdopen(file, "wb") |
|
|
@ -226,6 +228,8 @@ class nnmclub(object): |
|
|
|
print(path + " " + url) |
|
|
|
print(path + " " + url) |
|
|
|
|
|
|
|
|
|
|
|
def search(self, what, cat='all'): |
|
|
|
def search(self, what, cat='all'): |
|
|
|
|
|
|
|
if self.blocked: |
|
|
|
|
|
|
|
return |
|
|
|
c = self.supported_categories[cat] |
|
|
|
c = self.supported_categories[cat] |
|
|
|
query = '{}tracker.php?nm={}&{}'.format(self.url, what.replace(" ", "+"), "f=-1" if c == '-1' else "c=" + c) |
|
|
|
query = '{}tracker.php?nm={}&{}'.format(self.url, what.replace(" ", "+"), "f=-1" if c == '-1' else "c=" + c) |
|
|
|
response = self._catch_error_request(query) |
|
|
|
response = self._catch_error_request(query) |
|
|
@ -260,6 +264,12 @@ class nnmclub(object): |
|
|
|
logging.error(e) |
|
|
|
logging.error(e) |
|
|
|
raise 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 |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|