2022-03-14 09:16:22 +03:00
|
|
|
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
|
|
|
|
|
2019-05-04 22:38:06 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-03-14 09:16:22 +03:00
|
|
|
|
2019-05-04 22:38:06 +03:00
|
|
|
class Searcher(object):
|
|
|
|
base_url = None
|
|
|
|
search_path = None
|
|
|
|
cookies = {}
|
|
|
|
headers = {}
|
|
|
|
name = 'BaseClass'
|
2022-03-14 09:16:22 +03:00
|
|
|
|
2019-05-04 22:38:06 +03:00
|
|
|
def __init__(self):
|
2022-03-14 09:16:22 +03:00
|
|
|
self.session = Session()
|
|
|
|
self.session.proxies.update(proxies())
|
2019-05-05 22:16:27 +03:00
|
|
|
self.headers = {
|
2022-03-14 09:16:22 +03:00
|
|
|
'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',
|
2019-05-05 22:16:27 +03:00
|
|
|
'Referer': self.base_url
|
2022-03-14 09:16:22 +03:00
|
|
|
}
|
|
|
|
|
2019-05-04 22:38:06 +03:00
|
|
|
def prepare(self):
|
2022-03-14 09:16:22 +03:00
|
|
|
"""Login or something else if needed"""
|
2019-05-05 22:16:27 +03:00
|
|
|
return True
|
2022-03-14 09:16:22 +03:00
|
|
|
|
2019-05-04 22:38:06 +03:00
|
|
|
def search(self, query):
|
2019-05-05 22:16:27 +03:00
|
|
|
if self.prepare():
|
|
|
|
try:
|
|
|
|
url_constructor = urljoin_partial(self.base_url)
|
2022-03-14 09:16:22 +03:00
|
|
|
s_url = self.normalize_url(url_constructor(self.search_path.format(quote(query))))
|
2019-05-05 22:16:27 +03:00
|
|
|
resp = self.session.get(s_url, cookies=self.cookies, headers=self.headers)
|
2022-03-14 09:16:22 +03:00
|
|
|
parser = HTMLement('body')
|
|
|
|
parser.feed(resp.text)
|
|
|
|
# todo отладка
|
|
|
|
xbmc.log(f'SEARCH BODY:\n{resp.text}')
|
|
|
|
#
|
|
|
|
return self.process(parser.close())
|
2019-05-05 22:16:27 +03:00
|
|
|
except:
|
|
|
|
return []
|
|
|
|
else:
|
|
|
|
return []
|
2022-03-14 09:16:22 +03:00
|
|
|
|
2019-05-04 22:38:06 +03:00
|
|
|
def process(self, body):
|
2022-03-14 09:16:22 +03:00
|
|
|
"""Process element tree"""
|
|
|
|
|
2019-05-05 22:16:27 +03:00
|
|
|
def normalize_url(self, url):
|
|
|
|
return url
|