добавлен поисковик kinozal.tv

This commit is contained in:
Бородин Роман committed 2019-05-05 22:16:27 +03:00
1 parent b3a8e55bc0
commit 77f369a3f5
9 files changed
+145 -19

No files matched your search

+1 -1
View File
@@ -66,7 +66,7 @@ class Session(urlquick.Session):
# Make first connection to server
response = self.send_request(conn, req)
# Add connection to the pool if the response is not set to close
if not response.will_close:
pool[req.host] = conn
+18 -13
View File
@@ -23,21 +23,26 @@ class Searcher(object):
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):
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)
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 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
}
def normalize_url(self, url):
return url
+57
View File
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
from . import Searcher, urljoin_partial, ResultItem
from ..settings import option
from ..utils import notify, localize
from codequick.listing import local_image # @UnresolvedImport
class SearchEngine(Searcher):
base_url = option['kinozal_url']
search_path = '/browse.php?s={}&g=0&c=0&v=0&d=0&w=0&t=1&f=0'
name = 'Kinozal.tv'
icon = 'searcher_kinozal.png'
enabled = option.get_boolean('kinozal_enable') # @UndefinedVariable
def prepare(self):
if self.cookies:
c_uid = self.cookies.get('uid', None)
c_pass = self.cookies.get('pass', None)
if c_uid and c_pass:
return True
return self.login()
def process(self, body):
url_constructor = urljoin_partial(self.base_url)
rows = list(filter(lambda x: x.get('class') in ['first bg', 'bg'], body.findall('.//tr[@class]')))
for r in rows:
link = r.find('.//td[@class="nam"]/a')
url_part = link.get('href').strip().split('=')[1]
url = url_constructor(u'/download.php?id={}'.format(url_part))
title = link.text
seeders = int(r.find('.//td[@class="sl_s"]').text.strip())
leachers = int(r.find('.//td[@class="sl_p"]').text.strip())
size = list(
list(filter(lambda x: x.text.strip().endswith((u'ГБ', u'МБ')),
r.findall('.//td[@class="s"]'))
)[0].text.strip()
)[0].strip()
yield ResultItem(url, title, size, seeders, leachers, self.icon, self.cookies, self.base_url)
def login(self):
user = option['kinozal_login']
password = option['kinozal_password']
try:
if not user or not password:
raise Exception
resp = self.session.post('{}/takelogin.php'.format(self.base_url), data={'username': user, 'password': password, 'returnto': ''},
cookies={}, headers=self.headers, allow_redirects=False)
if not resp.ok:
raise Exception
cookies = resp.cookies
c_uid = cookies.get('uid', None)
c_pass = cookies.get('pass', None)
if not c_uid or not c_pass:
raise Exception
self.cookies = cookies
return True
except:
notify('Kinozal.tv', localize(33056), local_image.format('searcher_kinozal.png'))
return False
def normalize_url(self, url):
return url.encode('cp1251')
+3 -2
View File
@@ -1,11 +1,12 @@
from . import Searcher, urljoin_partial, ResultItem
from ..settings import option
class SearchEngine(Searcher):
#base_url = 'http://new-tor.top'
base_url = 'http://rutor.info'
base_url = option['rutor_url']
search_path = '/search/0/0/100/2/{}'
name = 'RuTor.org'
icon = 'searcher_rutor.png'
enabled = option.get_boolean('rutor_enable') # @UndefinedVariable
def process(self, body):
url_constructor = urljoin_partial(self.base_url)
rows = list(filter(lambda x: len(x.findall('.//a')) == 3, body.findall('.//tr')))
+4
View File
@@ -13,6 +13,10 @@ if py3:
else:
from urllib import pathname2url
def notify(heading, message, icon=xbmcgui.NOTIFICATION_INFO):
n = xbmcgui.Dialog()
n.notification(heading, message, icon, time=5, sound=True)
def localize(sid):
return addon_data.getLocalizedString(sid)
def store_torrent_file(file_bytes):