Версия для Kodi 19
This commit is contained in:
1 parent
e5bd0ca668
commit
baf6d0c369
8 files changed
+235
-203
No files matched your search
@@ -1,8 +1,10 @@
|
||||
from codequick.utils import urljoin_partial # @UnresolvedImport
|
||||
import urlquick # @UnresolvedImport
|
||||
from ..settings import option
|
||||
from ..overrrides import session
|
||||
#import xbmc
|
||||
import xbmc
|
||||
from codequick.utils import urljoin_partial
|
||||
from ..overrrides.session import proxies
|
||||
from requests.sessions import Session
|
||||
from htmlement import HTMLement
|
||||
from urllib.parse import quote
|
||||
|
||||
|
||||
class ResultItem(object):
|
||||
def __init__(self, url, title, size, seeders, leachers, icon='video.png', cookies={}, referer=''):
|
||||
@@ -15,34 +17,46 @@ class ResultItem(object):
|
||||
self.cookies = cookies
|
||||
self.referer = referer
|
||||
|
||||
|
||||
class Searcher(object):
|
||||
base_url = None
|
||||
search_path = None
|
||||
cookies = {}
|
||||
headers = {}
|
||||
name = 'BaseClass'
|
||||
|
||||
def __init__(self):
|
||||
self.session = session.Session()
|
||||
self.session = Session()
|
||||
self.session.proxies.update(proxies())
|
||||
self.headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 YaBrowser/14.10.2062.12061 Safari/537.36',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Chrome/37.0.2062.124 YaBrowser/14.10.2062.12061 Safari/537.36',
|
||||
'Referer': self.base_url
|
||||
}
|
||||
}
|
||||
|
||||
def prepare(self):
|
||||
'''Login or something else if needed'''
|
||||
"""Login or something else if needed"""
|
||||
return True
|
||||
|
||||
def search(self, query):
|
||||
if self.prepare():
|
||||
try:
|
||||
url_constructor = urljoin_partial(self.base_url)
|
||||
s_url = self.normalize_url(url_constructor(self.search_path.format(urlquick.quote(query))))
|
||||
s_url = self.normalize_url(url_constructor(self.search_path.format(quote(query))))
|
||||
resp = self.session.get(s_url, cookies=self.cookies, headers=self.headers)
|
||||
body = resp.parse('body')
|
||||
return self.process(body)
|
||||
parser = HTMLement('body')
|
||||
parser.feed(resp.text)
|
||||
# todo отладка
|
||||
xbmc.log(f'SEARCH BODY:\n{resp.text}')
|
||||
#
|
||||
return self.process(parser.close())
|
||||
except:
|
||||
return []
|
||||
else:
|
||||
return []
|
||||
|
||||
def process(self, body):
|
||||
'''Process element tree'''
|
||||
"""Process element tree"""
|
||||
|
||||
def normalize_url(self, url):
|
||||
return url
|
||||
@@ -1,15 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import xbmc
|
||||
|
||||
from . import Searcher, urljoin_partial, ResultItem
|
||||
from ..settings import option
|
||||
from ..utils import notify, localize
|
||||
from codequick.listing import local_image # @UnresolvedImport
|
||||
from codequick.listing import local_image
|
||||
|
||||
|
||||
class SearchEngine(Searcher):
|
||||
base_url = option['kinozal_url']
|
||||
search_path = '/browse.php?s={}&t=1'
|
||||
name = 'Kinozal.tv'
|
||||
icon = 'searcher_kinozal.png'
|
||||
enabled = option.get_boolean('kinozal_enable') # @UndefinedVariable
|
||||
enabled = option.get_boolean('kinozal_enable')
|
||||
|
||||
def prepare(self):
|
||||
if self.cookies:
|
||||
c_uid = self.cookies.get('uid', None)
|
||||
@@ -17,6 +21,7 @@ class SearchEngine(Searcher):
|
||||
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]')))
|
||||
@@ -28,20 +33,31 @@ class SearchEngine(Searcher):
|
||||
seeders = int(r.find('.//td[@class="sl_s"]').text.strip())
|
||||
leachers = int(r.find('.//td[@class="sl_p"]').text.strip())
|
||||
size_l = list(filter(lambda x: x.text.strip().endswith((u'ГБ', u'МБ')),
|
||||
r.findall('.//td[@class="s"]'))
|
||||
)
|
||||
r.findall('.//td[@class="s"]'))
|
||||
)
|
||||
size = size_l[0].text.strip() if len(size_l) else '0'
|
||||
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': ''},
|
||||
resp = self.session.post('{}/takelogin.php'.format(self.base_url),
|
||||
data={'username': user, 'password': password, 'returnto': ''},
|
||||
cookies={}, headers=self.headers, allow_redirects=False)
|
||||
# todo отладка
|
||||
xbmc.log(f'Kinozal LOGIN BODY:\n{resp.text}')
|
||||
#
|
||||
|
||||
if not resp.ok:
|
||||
raise Exception
|
||||
|
||||
# todo отладка
|
||||
xbmc.log(f'LOGIN COOKIE:\n{resp.cookies}')
|
||||
#
|
||||
|
||||
cookies = resp.cookies
|
||||
c_uid = cookies.get('uid', None)
|
||||
c_pass = cookies.get('pass', None)
|
||||
@@ -52,5 +68,6 @@ class SearchEngine(Searcher):
|
||||
except:
|
||||
notify(self.name, localize(33056), local_image.format(self.icon))
|
||||
return False
|
||||
|
||||
def normalize_url(self, url):
|
||||
return url.encode('cp1251')
|
||||
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import xbmc
|
||||
|
||||
from . import Searcher, urljoin_partial, ResultItem
|
||||
from ..settings import option
|
||||
from ..utils import notify, localize
|
||||
@@ -43,6 +45,11 @@ class SearchEngine(Searcher):
|
||||
cookies={}, headers=self.headers, allow_redirects=False)
|
||||
if not resp.ok:
|
||||
raise Exception
|
||||
|
||||
# todo отладка
|
||||
xbmc.log(f'RuTracker LOGIN BODY:\n{resp.text}')
|
||||
#
|
||||
|
||||
cookies = resp.cookies
|
||||
bb_session = cookies.get('bb_session', None)
|
||||
if not bb_session:
|
||||
|
||||
Reference in new issue
Block a user