2019-05-04 22:38:06 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from codequick import Route, Resolver, Listitem, utils, run # @UnresolvedImport
|
|
|
|
from codequick.storage import PersistentList # @UnresolvedImport
|
|
|
|
import os.path
|
|
|
|
import xbmcgui, xbmc
|
|
|
|
from resources.lib.searchers import rutor
|
|
|
|
from resources.lib.utils import localize, store_torrent_file, get_engine
|
|
|
|
from resources.lib.overrrides.session import torrent_file_fetch
|
2019-05-05 10:16:32 +03:00
|
|
|
from resources.lib.player import VideoLoop
|
2019-05-04 22:38:06 +03:00
|
|
|
|
|
|
|
video_extensions = ('.mp4', '.avi', '.3gp', '.ogv', '.mkv', '.ts', '.mpg', '.mpeg', '.webm', '.flv', '.vob')
|
|
|
|
|
|
|
|
search_engines = [
|
|
|
|
rutor.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):
|
|
|
|
@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
|
|
|
|
@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):
|
|
|
|
@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))
|
|
|
|
for p, se in zip(range(0, 100, 100 / len(search_engines)), search_engines):
|
|
|
|
progress.update(p, line1=se.name)
|
|
|
|
found_items.extend(se().search(search_query))
|
|
|
|
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
|
|
|
|
@Route.register
|
|
|
|
def open_torrent(plugin, url='--back--', cookies={}, referer='', path=''):
|
|
|
|
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': i}
|
|
|
|
)
|
|
|
|
item.art.local_thumb('video.png')
|
|
|
|
yield item
|
|
|
|
else:
|
|
|
|
yield None
|
|
|
|
@Route.register
|
|
|
|
def play_file(plugin, t_full_path, f_index):
|
|
|
|
vl = VideoLoop(t_full_path)
|
|
|
|
vl.start(f_index)
|
|
|
|
return False
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run()
|