63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
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=''):
|
|
self.url = url
|
|
self.title = title
|
|
self.size = size
|
|
self.seeders = seeders
|
|
self.leachers = leachers
|
|
self.icon = icon
|
|
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()
|
|
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',
|
|
'Referer': self.base_url
|
|
}
|
|
|
|
def prepare(self):
|
|
"""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(quote(query))))
|
|
resp = self.session.get(s_url, cookies=self.cookies, headers=self.headers)
|
|
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"""
|
|
|
|
def normalize_url(self, url):
|
|
return url
|