plugin.video.torrenter3/resources/lib/searchers/kinozal.py

56 lines
2.5 KiB
Python

# -*- 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['kinozal_url']
search_path = '/browse.php?s={}&g=0&c=0&v=0&d=0&w=0&t=1&f=0'
name = 'Kinozal.tv'
icon = 'searcher_kinozal.png'
enabled = option.get_boolean('kinozal_enable') # @UndefinedVariable
def prepare(self):
if self.cookies:
c_uid = self.cookies.get('uid', None)
c_pass = self.cookies.get('pass', None)
if c_uid and c_pass:
return True
return self.login()
def process(self, body):
url_constructor = urljoin_partial(self.base_url)
rows = list(filter(lambda x: x.get('class') in ['first bg', 'bg'], body.findall('.//tr[@class]')))
for r in rows:
link = r.find('.//td[@class="nam"]/a')
url_part = link.get('href').strip().split('=')[1]
url = url_constructor(u'/download.php?id={}'.format(url_part))
title = link.text
seeders = int(r.find('.//td[@class="sl_s"]').text.strip())
leachers = int(r.find('.//td[@class="sl_p"]').text.strip())
size = list(filter(lambda x: x.text.strip().endswith((u'ГБ', u'МБ')),
r.findall('.//td[@class="s"]'))
)[0].text.strip()
yield ResultItem(url, title, size, seeders, leachers, self.icon, self.cookies, self.base_url)
def login(self):
user = option['kinozal_login']
password = option['kinozal_password']
try:
if not user or not password:
raise Exception
resp = self.session.post('{}/takelogin.php'.format(self.base_url), data={'username': user, 'password': password, 'returnto': ''},
cookies={}, headers=self.headers, allow_redirects=False)
if not resp.ok:
raise Exception
cookies = resp.cookies
c_uid = cookies.get('uid', None)
c_pass = cookies.get('pass', None)
if not c_uid or not c_pass:
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')