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

44 lines
1.5 KiB
Python
Raw Normal View History

2019-05-04 22:38:06 +03:00
from codequick.utils import urljoin_partial # @UnresolvedImport
import urlquick # @UnresolvedImport
from ..settings import option
from ..overrrides import session
#import xbmc
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.Session()
def prepare(self):
'''Login or something else if needed'''
def search(self, query):
self.prepare()
url_constructor = urljoin_partial(self.base_url)
s_url = url_constructor(self.search_path.format(urlquick.quote(query)))
self.set_headers()
resp = self.session.get(s_url, cookies=self.cookies, headers=self.headers)
self.cookies = resp.cookies
body = resp.parse('body')
return self.process(body)
def process(self, body):
'''Process element tree'''
def set_headers(self):
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
}