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

49 lines
1.6 KiB
Python

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()
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(urlquick.quote(query))))
resp = self.session.get(s_url, cookies=self.cookies, headers=self.headers)
body = resp.parse('body')
return self.process(body)
except:
return []
else:
return []
def process(self, body):
'''Process element tree'''
def normalize_url(self, url):
return url