You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

146 lines
5.8 KiB

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from codequick import Route, Script, Listitem, utils, run # @UnresolvedImport
from codequick.storage import PersistentList # @UnresolvedImport
import os.path
import xbmcgui, xbmc
from resources.lib.searchers import rutor, kinozal, rutracker
from resources.lib.utils import localize, store_torrent_file, get_engine
from resources.lib.overrrides.session import torrent_file_fetch
from resources.lib.player import VideoLoop
video_extensions = ('.mp4', '.avi', '.3gp', '.ogv', '.mkv', '.ts', '.mpg', '.mpeg', '.webm', '.flv', '.vob')
search_engines = [
rutor.SearchEngine,
kinozal.SearchEngine,
rutracker.SearchEngine
]
ROOT = os.path.abspath(os.path.dirname(__file__))
ICON_DIR = os.path.join(ROOT, 'resources', 'icons')
@Route.register
def root(plugin, content_type='video'):
@Route.register_delayed
def set_view():
xbmc.executebuiltin('Container.SetViewMode("500")')
def build_item(a):
cb, name, image = a
i = Listitem.from_dict(cb, name)
i.art.local_thumb(image)
return i
return map(build_item, (
(search_history, localize(33052), 'history2.png'),
(new_search, localize(33053), 'search.png')
))
@Route.register
def search_history(plugin):
try:
@Route.register_delayed
def set_view():
xbmc.executebuiltin('Container.SetViewMode("51")')
h_list = PersistentList('search_history')
for i in h_list:
item = Listitem.from_dict(search, i, params={'search_query': i})
item.art.local_thumb('search.png')
yield item
else:
yield None
except:
yield False
@Route.register
def new_search(plugin):
q = utils.keyboard('Поиск')
if not q:
return False
return search(plugin, q)
@Route.register
def search(plugin, search_query, thumb=None):
try:
@Route.register_delayed
def set_view():
xbmc.executebuiltin('Container.SetViewMode("51")')
with PersistentList('search_history') as h_list:
if search_query in h_list:
del h_list[h_list.index(search_query)]
h_list.insert(0, search_query)
progress = xbmcgui.DialogProgress()
found_items = []
progress.create(localize(33054))
search_in = list(filter(lambda x: x.enabled, search_engines))
for p, se in zip(range(0, 100, 100 / len(search_in)), search_in):
progress.update(p, line1=se.name)
found_items.extend(se().search(search_query))
#open('/tmp/t.t', 'w').write(repr(list(map(lambda x: x.url, found_items))))
res_items = []
for i in sorted(found_items, key=lambda x: x.seeders, reverse=True):
if '2160p' in i.title: hd = '[2160p/{}] '.format(i.size)
elif '1080p' in i.title: hd = '[1080p/{}] '.format(i.size)
elif '720p' in i.title: hd = '[720p/{}] '.format(i.size)
else: hd = ''
item = Listitem.from_dict(
open_torrent,
'{}{} {} ({}/{})'.format(hd, i.title, i.size, i.seeders, i.leachers),
params={'url': i.url, 'cookies': i.cookies, 'referer': i.referer}
)
if thumb:
item.art['thumb'] = thumb
else:
item.art.local_thumb(i.icon)
res_items.append(item)
progress.close()
return res_items
except:
return False
@Route.register
def open_torrent(plugin, url='--back--', cookies={}, referer='', path=''):
try:
if url == '--back--':
xbmc.executebuiltin('ActivateWindow("home")')
yield False
else:
@Route.register_delayed
def set_view():
xbmc.executebuiltin('Container.SetViewMode("51")')
tf = torrent_file_fetch(url, referer, cookies)
if not tf: yield False
t_full_path = store_torrent_file(tf)
e = get_engine(t_full_path)
files = sorted(list(filter(
lambda x: x.name.decode('utf-8').startswith(path) and x.name.decode('utf-8').lower().endswith(video_extensions), e.list_from_info(media_types=['video']))),
key=lambda x: x.name)
dirs = list(set(list(map( lambda x: x.name.decode('utf-8')[len(path):].lstrip('/').split('/')[0], filter( lambda x: len(x.name.decode('utf-8')[len(path):].lstrip('/').split('/')) > 1, files ) ))))
for d in sorted(dirs):
item = Listitem.from_dict(open_torrent,
d,
params={'url': url, 'cookies': cookies, 'referer': referer, 'path': '{}/{}'.format(
path, d
) if path != '' else d}
)
item.art.local_thumb('folder.png')
yield item
for i in range(len(files)):
f = files[i]
p = f.name.decode('utf-8')[len(path):].lstrip('/').split('/')
if len(p) == 1:
item = Listitem.from_dict(play_file,
'{} ({:.3f} GB)'.format(p[0], f.size / 1024.0 / 1024.0 /1024.0),
params={'t_full_path': t_full_path, 'f_index': f.index}
)
item.art.local_thumb('video.png')
yield item
else:
yield None
except:
yield False
@Script.register
def play_file(plugin, t_full_path, f_index):
try:
vl = VideoLoop(t_full_path)
vl.start(f_index)
return False
except:
return False
if __name__ == '__main__':
run()