Добавлен поисковик RuTracker. SOCKS-прокси для подключения к трекерам

This commit is contained in:
Бородин Роман committed 2020-04-28 22:24:21 +03:00
1 parent be14440f2f
commit c4e6d7763e
10 files changed
+109 -18

No files matched your search

+1 -1
View File
@@ -49,7 +49,7 @@ class SearchEngine(Searcher):
self.cookies = cookies
return True
except:
notify('Kinozal.tv', localize(33056), local_image.format('searcher_kinozal.png'))
notify(self.name, localize(33056), local_image.format(self.icon))
return False
def normalize_url(self, url):
return url.encode('cp1251')
+14 -11
View File
@@ -11,14 +11,17 @@ class SearchEngine(Searcher):
url_constructor = urljoin_partial(self.base_url)
rows = list(filter(lambda x: len(x.findall('.//a')) == 3, body.findall('.//tr')))
for r in rows:
links = r.findall('.//a')
url = url_constructor(links[0].get('href').strip())
title = links[2].text
seeders = int(list(r.findall('.//span[@class="green"]')[0].itertext())[0].strip())
leachers = int(list(r.findall('.//span[@class="red"]')[0].itertext())[0].strip())
size = list(
list(filter(lambda x: len(list(x.itertext())) == 1 and list(x.itertext())[0].strip().endswith(('GB', 'MB')),
r.findall('.//td'))
)[0].itertext()
)[0].strip()
yield ResultItem(url, title, size, seeders, leachers, self.icon, self.cookies, self.base_url)
try:
links = r.findall('.//a')
url = url_constructor(links[0].get('href').strip())
title = links[2].text
seeders = int(list(r.findall('.//span[@class="green"]')[0].itertext())[0].strip())
leachers = int(list(r.findall('.//span[@class="red"]')[0].itertext())[0].strip())
size = list(
list(filter(lambda x: len(list(x.itertext())) == 1 and list(x.itertext())[0].strip().endswith(('GB', 'MB')),
r.findall('.//td'))
)[0].itertext()
)[0].strip()
yield ResultItem(url, title, size, seeders, leachers, self.icon, self.cookies, self.base_url)
except:
continue
+55
View File
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
from . import Searcher, urljoin_partial, ResultItem
from ..settings import option
from ..utils import notify, localize
from codequick.listing import local_image # @UnresolvedImport
class SearchEngine(Searcher):
base_url = option['rutracker_url']
search_path = '/forum/tracker.php?nm={}'
name = 'RuTracker.org'
icon = 'searcher_rutracker.png'
enabled = option.get_boolean('rutracker_enable') # @UndefinedVariable
def prepare(self):
if self.cookies:
bb_session = self.cookies.get('bb_session', None)
if bb_session:
return True
return self.login()
def process(self, body):
url_constructor = urljoin_partial(self.base_url)
rows = body.findall('.//div[@id="search-results"]/table/tbody/tr')
for r in rows:
link = list(filter(lambda x: 't-title' in x.attrib['class'], r.findall('.//td')))[0].find('.//a')
url_part = link.get('href').strip().split('=')[1]
url = url_constructor(u'/forum/dl.php?t={}'.format(url_part))
title = link.text
seeders_el = r.find('.//*[@class="seedmed"]')
seeders = int(seeders_el.text.strip() if seeders_el is not None else 0)
leachers = int(list(filter(lambda x: 'leechmed' in x.attrib['class'], r.findall('.//td')))[0].text.strip())
size = ' '.join(list(filter(lambda x: 't-title' in x.attrib['class'], r.findall('.//td')))[0].find('.//a').text.strip().split(' ')[:2])
yield ResultItem(url, title, size, seeders, leachers, self.icon, self.cookies, self.base_url)
def login(self):
user = option['rutracker_login']
password = option['rutracker_password']
try:
if not user or not password:
raise Exception
resp = self.session.post('{}/forum/login.php'.format(self.base_url), data={'login_username': user,
'login_password': password,
'login': '%C2%F5%EE%E4',
'redirect': 'index.php'},
cookies={}, headers=self.headers, allow_redirects=False)
if not resp.ok:
raise Exception
cookies = resp.cookies
bb_session = cookies.get('bb_session', None)
if not bb_session:
raise Exception
self.cookies = cookies
return True
except:
notify(self.name, localize(33056), local_image.format(self.icon))
return False
def normalize_url(self, url):
return url.encode('cp1251')
+8 -1
View File
@@ -39,10 +39,17 @@ def file_url(path):
return path
def get_engine(torrent_uri):
if option.get_boolean('use_socks_for_trackers'): # @UndefinedVariable
proxy = {
'host': option['socks_ip'],
'port': int(option['socks_port'])
}
else:
proxy = None
return Engine(uri=file_url(torrent_uri), download_path=storage_download_dir,
encryption=1, keep_complete=False, keep_incomplete=False,
dht_routers=["router.bittorrent.com:6881", "router.utorrent.com:6881"], use_random_port=False, listen_port=6881,
user_agent='', enable_dht=True)
user_agent='', enable_dht=True, proxy=proxy)
while not option['storage_dir']:
dialog = xbmcgui.Dialog()
dialog.ok(localize(33000), localize(33051))