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

63 lines
1.9 KiB
Python
Raw Normal View History

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())
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',
'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"""
return True
2022-03-14 09:16:22 +03:00
2019-05-04 22:38:06 +03:00
def search(self, query):
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))))
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 отладка
2022-03-20 00:15:29 +03:00
# xbmc.log(f'SEARCH BODY:\n{resp.text}')
2022-03-14 09:16:22 +03:00
#
return self.process(parser.close())
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"""
def normalize_url(self, url):
return url