2019-05-05 22:16:27 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
2022-03-14 09:16:22 +03:00
|
|
|
import xbmc
|
|
|
|
|
2019-05-05 22:16:27 +03:00
|
|
|
from . import Searcher, urljoin_partial, ResultItem
|
|
|
|
from ..settings import option
|
|
|
|
from ..utils import notify, localize
|
2022-03-14 09:16:22 +03:00
|
|
|
from codequick.listing import local_image
|
|
|
|
|
2019-05-05 22:16:27 +03:00
|
|
|
|
|
|
|
class SearchEngine(Searcher):
|
|
|
|
base_url = option['kinozal_url']
|
2020-12-05 23:18:47 +03:00
|
|
|
search_path = '/browse.php?s={}&t=1'
|
2019-05-05 22:16:27 +03:00
|
|
|
name = 'Kinozal.tv'
|
|
|
|
icon = 'searcher_kinozal.png'
|
2022-03-14 09:16:22 +03:00
|
|
|
enabled = option.get_boolean('kinozal_enable')
|
|
|
|
|
2019-05-05 22:16:27 +03:00
|
|
|
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()
|
2022-03-14 09:16:22 +03:00
|
|
|
|
2019-05-05 22:16:27 +03:00
|
|
|
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())
|
2020-12-05 23:18:47 +03:00
|
|
|
size_l = list(filter(lambda x: x.text.strip().endswith((u'ГБ', u'МБ')),
|
2022-03-14 09:16:22 +03:00
|
|
|
r.findall('.//td[@class="s"]'))
|
|
|
|
)
|
2020-12-05 23:18:47 +03:00
|
|
|
size = size_l[0].text.strip() if len(size_l) else '0'
|
2019-05-05 22:16:27 +03:00
|
|
|
yield ResultItem(url, title, size, seeders, leachers, self.icon, self.cookies, self.base_url)
|
2022-03-14 09:16:22 +03:00
|
|
|
|
2019-05-05 22:16:27 +03:00
|
|
|
def login(self):
|
|
|
|
user = option['kinozal_login']
|
|
|
|
password = option['kinozal_password']
|
|
|
|
try:
|
|
|
|
if not user or not password:
|
|
|
|
raise Exception
|
2022-03-14 09:16:22 +03:00
|
|
|
resp = self.session.post('{}/takelogin.php'.format(self.base_url),
|
|
|
|
data={'username': user, 'password': password, 'returnto': ''},
|
2019-05-05 22:16:27 +03:00
|
|
|
cookies={}, headers=self.headers, allow_redirects=False)
|
2022-03-14 09:16:22 +03:00
|
|
|
# todo отладка
|
2022-03-20 00:15:29 +03:00
|
|
|
# xbmc.log(f'Kinozal LOGIN BODY:\n{resp.text}')
|
2022-03-14 09:16:22 +03:00
|
|
|
#
|
|
|
|
|
2019-05-05 22:16:27 +03:00
|
|
|
if not resp.ok:
|
|
|
|
raise Exception
|
2022-03-14 09:16:22 +03:00
|
|
|
|
|
|
|
# todo отладка
|
2022-03-20 00:15:29 +03:00
|
|
|
# xbmc.log(f'LOGIN COOKIE:\n{resp.cookies}')
|
2022-03-14 09:16:22 +03:00
|
|
|
#
|
|
|
|
|
2019-05-05 22:16:27 +03:00
|
|
|
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:
|
2020-04-28 22:24:21 +03:00
|
|
|
notify(self.name, localize(33056), local_image.format(self.icon))
|
2019-05-05 22:16:27 +03:00
|
|
|
return False
|
2022-03-14 09:16:22 +03:00
|
|
|
|
2019-05-05 22:16:27 +03:00
|
|
|
def normalize_url(self, url):
|
|
|
|
return url.encode('cp1251')
|