diff --git a/platformcode/infoplus.py b/platformcode/infoplus.py index 3209f82d..a040ac9d 100644 --- a/platformcode/infoplus.py +++ b/platformcode/infoplus.py @@ -1,1093 +1,478 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------ -# infoplus ventana con información del Item +# infoplus window with item information # ------------------------------------------------------------ - -from future import standard_library -standard_library.install_aliases() - -import re, sys, xbmc, xbmcaddon, xbmcgui -PY3 = False -if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int - -from builtins import range -from threading import Thread -from core import httptools, scrapertools, filetools, tmdb +import xbmc, xbmcgui, json, sys, requests, re +from core import support, tmdb, filetools from core.item import Item -from core.support import typo, dbg -from core.scrapertools import decodeHtmlentities as dhe -from platformcode import config, logger, platformtools +from platformcode import config, platformtools +from platformcode.logger import log +from core.scrapertools import decodeHtmlentities, htmlclean -info_language = ["de", "en", "es", "fr", "it", "pt"] # from videolibrary.json -def_lang = info_language[config.get_setting("info_language", "videolibrary")] +PY3 = False +if sys.version_info[0] >= 3: PY3 = True +if PY3: from concurrent import futures +else: from concurrent_py2 import futures -max_poster = 6 +info_list = [] +SearchWindows = [] +api = 'k_0tdb8a8y' -global mainWindow -mainWindow = list() -ActorsWindow = None -TrailerWindow = None -relatedWindow = None -imagesWindow = None -ActorInfoWindow = None -SearchWindow = None -SearchWindows = list() +# Control ID +FANART = 30000 +NUMBER = 30001 +POSTER_BTN = 30010 +TITLE = 30002 +TAGLINE = 30003 +PLOT = 30004 +RATING_ICON = 30005 +RATING = 30006 +TRAILER = 30007 +SEARCH = 30008 +BTN_NEXT = 30009 +BTN_PREV = 30010 +LOADING = 30011 +COMMANDS = 30012 +RECOMANDED = TRAILERS = 30500 +CAST = 30501 +CASTMOVIES = 30502 -exit_loop = False - -ACTION_SHOW_FULLSCREEN = 36 -ACTION_GESTURE_SWIPE_LEFT = 511 -ACTION_SELECT_ITEM = 7 -ACTION_PREVIOUS_MENU = 10 -ACTION_MOVE_LEFT = 1 -ACTION_MOVE_RIGHT = 2 -ACTION_MOVE_UP = 3 -ACTION_MOVE_DOWN = 4 - -xinfoplus_set = config.get_setting("infoplus_set") - -def start(item, recommendations=[], from_window=False): - main_window = main(item=item, recommendations=recommendations, from_window=from_window) - try: - mainWindow.append(main_window) - main_window.doModal() - except: - return +# Actions +LEFT = 1 +RIGHT = 2 +UP = 3 +DOWN = 4 +EXIT = 10 +BACKSPACE = 92 -class main(xbmcgui.WindowDialog): + +def Main(item): + if type(item) == Item: + item.channel = item.from_channel + global ITEM + ITEM = item + Info = xbmcgui.ListItem(item.infoLabels['title']) + for key, value in item.infoLabels.items(): + Info.setProperty(key, str(value)) + else: + Info = item + + main = MainWindow('InfoPlus.xml', config.get_runtime_path()) + add({'class':main, 'info':Info, 'id':RECOMANDED, RECOMANDED:0, CAST:0}) + modal() + +class MainWindow(xbmcgui.WindowXMLDialog): def __init__(self, *args, **kwargs): - self.item = kwargs.get('item') - self.recommendations = kwargs.get('recommendations') - self.from_window = kwargs.get('from_window', False) - self.images = {} - - if self.item.contentType == "movie": - Type = "movie" - search_type = "movie" - rating_icon = imagepath('tmdb') - else: - Type = "serie" - search_type = "tv" - rating_icon = imagepath('tvdb') - - info_copy = dict(self.item.infoLabels) - self.item.infoLabels.pop("season", None) - self.item.infoLabels.pop("episode", None) - if not self.item.infoLabels["year"] and not self.item.infoLabels["tmdb_id"]: - platformtools.dialog_notification(config.get_localized_string(60471), config.get_localized_string(60472) % config.get_localized_string(60329)) - global mainWindow - self.close() - del mainWindow - return - - tmdb.set_infoLabels_item(self.item, True) - self.infoLabels = self.item.infoLabels - self.infoLabels["season"] = info_copy.get("season", None) - self.infoLabels["episode"] = info_copy.get("episode", None) - - if not self.infoLabels["tmdb_id"]: - platformtools.dialog_notification(config.get_localized_string(60473), config.get_localized_string(60474) % config.get_localized_string(60329)) - global mainWindow - self.close() - del mainWindow - return - - Title = typo(self.infoLabels.get("title"), 'bold') - if self.infoLabels.get("rating"): rating = typo(self.infoLabels["rating"], 'bold') - else: rating = typo('N/A', 'bold') - - self.infoLabels["plot"] = self.infoLabels.get("plot") - - thread = Thread(target=get_recomendations, args=[self.item, self.infoLabels, self.recommendations]) - thread.setDaemon(True) - thread.start() - - if self.infoLabels.get("status") == "Ended" and Type == "serie": status = config.get_localized_string(60478) - elif self.infoLabels.get("status") and Type == "serie": status = config.get_localized_string(60479) - else: status = "%s" - - if self.infoLabels.get("tagline") and Type == "serie": self.infoLabels["tagline"] = status % "(" + self.infoLabels["tagline"] + ")" - elif not self.infoLabels.get("tagline") and Type == "serie": self.infoLabels["tagline"] = status % config.get_localized_string(60480) % self.infoLabels.get("number_of_seasons", "---") - else: self.infoLabels["tagline"] = status % self.infoLabels.get("tagline", "") - - if self.infoLabels["tmdb_id"]: - otmdb = tmdb.Tmdb(id_Tmdb=self.infoLabels["tmdb_id"], tipo=search_type) - self.item.images = otmdb.result.get("images", {}) - for key, value in list(self.item.images.items()): - if not value: self.item.images.pop(key) - - if not self.infoLabels.get("originaltitle"): self.infoLabels["originaltitle"] = otmdb.result.get("original_title", otmdb.result.get("original_name", "")) - self.trailers = otmdb.get_videos() - if otmdb.result.get("runtime", 0): self.infoLabels["duration"] = int(otmdb.result.get("runtime", 0)) - else: - self.trailers = [] - - if self.item.contentType != "movie": - try: - # look for the theme of the series - Title = re.sub(r'\[.*?\]', '', Title) - Title = self.infoLabels.get("originaltitle", Title) - Title = re.sub("'", "", Title) - url_tvthemes = "http://televisiontunes.com/search.php?q=%s" % Title.replace(' ', '+') - - data = httptools.downloadpage(url_tvthemes).data - page_theme = scrapertools.find_single_match(data, r'.*?
(.*?)
') - if info: - bio = dhe(scrapertools.htmlclean(info.strip())) - actor_tmdb.result["biography"] = bio - else: - actor_tmdb.result["biography"] = config.get_localized_string(60504) - elif not actor_tmdb.result.get("biography"): - actor_tmdb.result["biography"] = config.get_localized_string(60504) - - #### Kodi 18 Compatibility #### + #### Compatibility with Kodi 18 #### if config.get_platform(True)['num_version'] < 18: self.setCoordinateResolution(2) - - self.background = xbmcgui.ControlImage(0, 0, 1280, 720, imagepath('white'), colorDiffuse='FF232323') - self.addControl(self.background) - - # TITLE - self.title = xbmcgui.ControlTextBox(40, 40, 750, 30, font=self.fonts["30"]) - self.addControl(self.title) - self.title.setAnimations([('WindowOpen', 'effect=slide start=-750,0 end=0,0 delay=100 time=200'), ('WindowClose', 'effect=slide start=0,0 end=-750,0 delay=100 time=200')]) - self.title.setText(self.nombre) - - # ACTOR INFO (PLOT) - self.info_actor = xbmcgui.ControlTextBox(40, 140, 760, 460, font=self.fonts["24"]) - self.addControl(self.info_actor) - self.info_actor.setAnimations([('WindowOpen', 'effect=slide start=-750,0 end=0,0 delay=100 time=200'), ('WindowClose', 'effect=slide start=0,0 end=-750,0 delay=100 time=200')]) - try: self.info_actor.autoScroll(10000, 2000, 30000) - except: xbmc.executebuiltin( config.get_localized_string(70500)) - self.info_actor.setText(typo(actor_tmdb.result.get("biography", config.get_localized_string(60504)),'bold')) - - # POSTER - self.thumbnail = xbmcgui.ControlImage(880, 40, 400, 600, self.thumbnail) - self.addControl(self.thumbnail) - self.thumbnail.setAnimations([('WindowOpen', 'effect=slide start=+400,0 end=0,0 delay=100 time=200'), ('WindowClose', 'effect=slide start=0,0 end=+400,0 delay=100 time=200')]) - xbmc.sleep(300) - - # Movies - self.Titles = [] - search_type = "cast" - if self.job != "actor": search_type = "crew" - ids = [] - for entradas in actor_tmdb.result.get("%s_credits" % Type, {}).get(search_type, []): - if entradas["id"] not in ids and entradas["poster_path"]: - ids.append(entradas["id"]) - thumbnail = "https://image.tmdb.org/t/p/original" - thumbnail += entradas["poster_path"] - if self.item.contentType == "movie": self.Titles.append([entradas["id"], entradas.get("title", entradas.get("original_title", "")), thumbnail]) - else: self.Titles.append([entradas["id"], entradas.get("title", entradas.get("original_title", "")), thumbnail]) - - self.dialog.update(40, config.get_localized_string(60505)) - self.max_movies = max_poster - self.idps = [] - self.buttons = [] - self.max_movies_buttons = [] - self.focus = 0 - i = 0 - count = 0 - self.btn_left = xbmcgui.ControlButton(0, 680, 40, 40, '', imagepath('previous_focus'), imagepath('previous_no_focus')) - self.addControl(self.btn_left) - self.buttons.append(self.btn_left) - for idp, title, photo in self.Titles: - if count % max_poster == 0: i = 0 - self.image = xbmcgui.ControlButton(40 + i, 420 + 260, 200, 300, '', photo, photo) - self.buttons.append(self.image) - if count < max_poster: - self.addControl(self.image) - self.image.setAnimations([('focus', 'effect=slide start=0,0 end=0,-260 time=200'),('unfocus', 'effect=slide start=-0,-260 end=0,0 time=200'),('WindowOpen', 'effect=slide start=0,40 end=0,0 delay=100 time=200 conditional=true'),('WindowClose', 'effect=slide start=0,0 end=0,40 delay=100 time=200 conditional=true')]) - self.idps.append([self.image, title, idp, photo]) - self.max_movies_buttons.append([self.image, title]) - i += 200 - count += 1 - xbmc.sleep(200) - - self.btn_right = xbmcgui.ControlButton(1240, 680, 40, 40, '', imagepath('next_focus'), imagepath('next_no_focus')) - self.addControl(self.btn_right) - self.buttons.append(self.btn_right) - xbmc.sleep(200) - self.dialog.close() - - - def onAction(self, action): - global exit_loop - if exit_loop: - exit_loop = False - - if action == ACTION_MOVE_RIGHT: - if self.getFocusId() not in [3012]: - if self.focus < len(self.buttons) - 1: - self.focus += 1 - while True: - id_focus = str(self.buttons[self.focus].getId()) - if xbmc.getCondVisibility('[Control.IsVisible(' + id_focus + ')]'): - self.setFocus(self.buttons[self.focus]) - break - self.focus += 1 - if self.focus == len(self.buttons): - break - elif self.getFocusId() in [3012]: - self.focus = 0 - self.setFocus(self.btn_left) - - if action == ACTION_MOVE_LEFT: - if self.getFocusId() not in [3005]: - if self.focus > 0: - self.focus -= 1 - while True: - id_focus = str(self.buttons[self.focus].getId()) - if xbmc.getCondVisibility('[Control.IsVisible(' + id_focus + ')]'): - self.setFocus(self.buttons[self.focus]) - break - self.focus -= 1 - if self.focus == len(self.buttons): - break - elif self.getFocusId() in [3005]: - self.focus = len(self.buttons) - 1 - self.setFocus(self.btn_right) - - if action == ACTION_PREVIOUS_MENU or action == ACTION_GESTURE_SWIPE_LEFT or action == 110 or action == 92: - exit_loop = True - self.close() - - if action == 105 or action == 6: - for button, title, id, poster in self.idps: - try: - if self.getFocusId() == button.getId() and self.btn_right: - self.focus = len(self.buttons) - 1 - xbmc.executebuiltin('SendClick(%s)' % self.btn_right.getId()) - except: - pass - - if action == 104 or action == 5: - for button, title, id, poster in self.idps: - try: - if self.getFocusId() == button.getId() and self.btn_left: - self.setFocus(self.btn_left) - xbmc.executebuiltin('SendClick(%s)' % self.btn_left.getId()) - except: - pass - - def onControl(self, control): - if control == self.btn_right: - try: - i = 1 - count = 0 - for photo, title in self.max_movies_buttons: - if i > self.max_movies - max_poster and i <= self.max_movies and count < max_poster: - self.removeControls([photo]) - count += 1 - elif i > self.max_movies and count < max_poster * 2: - self.addControl(photo) - photo.setAnimations([('focus', 'effect=slide start=0,0 end=0,-260 time=200'),('unfocus', 'effect=slide start=-0,-260 end=0,0 time=200'),('WindowOpen', 'effect=slide start=0,40 end=0,0 delay=100 time=200 conditional=true'),('WindowClose', 'effect=slide start=0,0 end=0,40 delay=100 time=200 conditional=true')]) - count += 1 - self.max_movies += 1 - xbmc.sleep(120) - i += 1 - xbmc.sleep(300) - except: - pass - elif control == self.btn_left: - try: - i = 1 - count = 0 - for photo, title in self.max_movies_buttons: - stay = max_poster + (self.max_movies % max_poster) - if stay == max_poster: - stay = max_poster * 2 - stay2 = self.max_movies % max_poster - if not stay2: - stay2 = max_poster - if i > self.max_movies - stay and count < max_poster: - self.addControl(photo) - photo.setAnimations([('focus', 'effect=slide start=0,0 end=0,-260 time=200'),('unfocus', 'effect=slide start=-0,-260 end=0,0 time=200'),('WindowOpen', 'effect=slide start=0,40 end=0,0 delay=100 time=200 conditional=true'),('WindowClose', 'effect=slide start=0,0 end=0,40 delay=100 time=200 conditional=true')]) - count += 1 - elif i > self.max_movies - stay2 and i <= self.max_movies and count < max_poster * 2: - self.removeControls([photo]) - count += 1 - self.max_movies -= 1 - i += 1 - if self.max_movies == max_poster: - self.btn_left.setVisible(False) - except: - pass - + if Info.getProperty('id'): + for item in get_movies(Info): + self.items.append(item) else: - for button, title, id, poster in self.idps: - if control == button: - new_item = self.item.clone(title=title,infoLabels={'tmdb_id':id}) - self.close() - start(new_item, from_window=True) + for item in get_recomendations(Info): + self.items.append(item) + for i, item in enumerate(get_cast(Info)): + if i == 0: actors_more_info(item) + self.cast.append(item) + self.getControl(LOADING).setVisible(False) + self.getControl(RECOMANDED).addItems(self.items) + self.getControl(FANART).setImage(Info.getProperty('fanart')) + self.getControl(CAST).addItems(self.cast) + if Info.getProperty('rating'): + self.getControl(RATING).setText(str(Info.getProperty('rating'))) + getFocus(self) - -class images(xbmcgui.WindowDialog): - def __init__(self, *args, **kwargs): - self.tmdb = kwargs.get("tmdb", {}) - - self.image_list = [] - - for key, value in self.tmdb.items(): - for detail in value: self.image_list.append('http://image.tmdb.org/t/p/original' + detail["file_path"]) - # for image in self.imdb: self.image_list.append(image["src"]) - # for image, title in self.mal: self.image_list.append(image) - - #### Kodi 18 Compatibility #### - if config.get_platform(True)['num_version'] < 18: self.setCoordinateResolution(2) - - self.background = xbmcgui.ControlImage(0, 0, 1280, 720, imagepath('white'), colorDiffuse='CC232323') - self.addControl(self.background) - main_image = self.image_list[0] if self.image_list else '' - self.main_image = xbmcgui.ControlImage(0, 0, 1280, 720, main_image, 2) - self.addControl(self.main_image) - - # BUTTON LEFT - self.btn_left = xbmcgui.ControlButton(0, 300, 60, 60, '', imagepath('previous_focus'), imagepath('previous_no_focus')) - self.addControl(self.btn_left) - self.btn_left.setAnimations([('WindowOpen', 'effect=slide start=-60,0 end=0,0 delay=100 time=200'),('WindowClose', 'effect=slide start=0,0 end=-60,0 delay=100 time=200')]) - - # BUTTON RIGHT - self.btn_right = xbmcgui.ControlButton(1220, 300, 60, 60, '', imagepath('next_focus'), imagepath('next_no_focus')) - self.addControl(self.btn_right) - self.btn_right.setAnimations([('WindowOpen', 'effect=slide start=60,0 end=0,0 delay=100 time=200'),('WindowClose', 'effect=slide start=0,0 end=60,0 delay=100 time=200')]) - - self.count = 0 + def onClick(self, control_id): + setFocus(self) + if control_id in [SEARCH]: + title = self.getControl(RECOMANDED).getSelectedItem().getProperty('title') + mode = self.getControl(RECOMANDED).getSelectedItem().getProperty('mediatype') + action = 'search' + # if title == Info.getProperty('title'): action = 'global_search' + # else: action = 'search' + self.close() + if self.getControl(RECOMANDED).getSelectedPosition() > 0: + Search(ITEM.clone(action=action, search_text=title)) + else: + Search(ITEM.clone(action=action, search_text=title, mode=mode)) + elif control_id in [TRAILER]: + info = self.getControl(RECOMANDED).getSelectedItem() + self.close() + Trailer(info) + elif control_id in [CAST]: + self.close() + Main(self.getControl(CAST).getSelectedItem()) + elif control_id in [BTN_NEXT]: + self.setFocusId(CAST) + elif control_id in [BTN_PREV]: + self.setFocusId(RECOMANDED) + elif control_id in [RECOMANDED]: + self.close() + Main(self.getControl(RECOMANDED).getSelectedItem()) def onAction(self, action): - if action == ACTION_PREVIOUS_MENU or action == ACTION_GESTURE_SWIPE_LEFT or action == 110 or action == 92: + if self.getFocusId() in [CAST, RECOMANDED]: + self.ids[self.getFocusId()] = self.getControl(self.getFocusId()).getSelectedPosition() + if self.getFocusId() in [CAST] and action not in [BACKSPACE, EXIT, UP, DOWN]: + actors_more_info(self.getControl(self.getFocusId()).getSelectedItem()) + if self.getFocusId() in [RECOMANDED]: + fanart = self.getControl(self.getFocusId()).getSelectedItem().getProperty('fanart') + rating = self.getControl(self.getFocusId()).getSelectedItem().getProperty('rating') + if not rating: rating = 'N/A' + self.getControl(FANART).setImage(fanart) + self.getControl(RATING).setText(rating) + if self.getFocus() > 0: + cast = [] + self.getControl(CAST).reset() + for actor in get_cast(self.getControl(self.getFocusId()).getSelectedItem()): + cast.append(actor) + self.getControl(CAST).addItems(cast) + action = action.getId() + if action in [BACKSPACE]: + self.close() + remove() + modal() + elif action in [EXIT]: self.close() - if action == ACTION_MOVE_RIGHT or action == ACTION_MOVE_DOWN: - self.count += 1 - if self.count > len(self.image_list) -1: self.count = 0 - self.main_image.setImage(self.image_list[self.count]) - if action == ACTION_MOVE_LEFT or action == ACTION_MOVE_UP: - self.count -= 1 - if self.count < 0: self.count = len(self.image_list) -1 - self.main_image.setImage(self.image_list[self.count]) +def Search(item): + if item.action == 'findvideos': XML = 'ServersWindow.xml' + else: XML = 'SearchWindow.xml' + global Info + Info = item + main = SearchWindow(XML, config.get_runtime_path()) + add({'class':main, 'info':item, 'id':RECOMANDED}) + modal() - - def onControl(self, control): - if control == self.btn_right: - self.count += 1 - if self.count > len(self.image_list) -1: self.count = 0 - self.main_image.setImage(self.image_list[self.count]) - - if control == self.btn_left: - self.count -= 1 - if self.count < 0: self.count = len(self.image_list) -1 - self.main_image.setImage(self.image_list[self.count]) - - -class Trailer(xbmcgui.WindowXMLDialog): - def Start(self, item, trailers): - self.item = item - from specials import trailertools - self.video_url, self.windows = trailertools.buscartrailer(self.item.clone(), trailers=trailers) - self.doModal() +class SearchWindow(xbmcgui.WindowXMLDialog): + def __init__(self, *args, **kwargs): + self.items = [] + self.itemlist = [] + self.commands = [] + self.ids = {} + self.channel = None def onInit(self): - #### Kodi 18 Compatibility#### - if config.get_platform(True)['num_version'] < 18: self.setCoordinateResolution(0) + #### Compatibility with Kodi 18 #### + if config.get_platform(True)['num_version'] < 18: + self.setCoordinateResolution(2) + if not self.items: + if Info.action == 'search' and Info.mode: + from specials.search import new_search + itemlist = new_search(Info) + elif Info.action == 'channel_search': + from specials.search import channel_search + itemlist = channel_search(Info) + else: + self.channel = __import__('channels.%s' % Info.channel, fromlist=["channels.%s" % Info.channel]) + if Info.action == 'search': itemlist = getattr(self.channel, 'search')(Info, Info.search_text) + else: itemlist = getattr(self.channel, Info.action)(Info) + if not itemlist: + if platformtools.dialog_yesno(config.get_localized_string(60473), config.get_localized_string(70820) % Info.channel): + remove() + self.close() + return Search(Info.clone(mode=Info.infoLabels['mediatype'])) + else: + remove() + self.close() + modal() + for item in itemlist: + if item.action not in ['save_download', 'add_pelicula_to_library', 'add_serie_to_library', ''] and item.infoLabels['title']: + if item.action == 'findvideos' and item.contentType in ['episode', 'tvshow']: + it = xbmcgui.ListItem(re.sub(r'\[[^\]]+\]', '', item.title)) + else: + it = xbmcgui.ListItem(item.infoLabels['title']) + it.setProperty('channel', item.channel) + it.setProperty('action', item.action) + it.setProperty('server', item.server) + it.setProperty('url', item.url) + for key, value in item.infoLabels.items(): + it.setProperty(key, str(value)) + if item.action == 'play': + it.setProperty('thumbnail', "https://raw.githubusercontent.com/kodiondemand/media/master/resources/servers/%s.png" % item.server.lower()) + self.items.append(it) + self.itemlist.append(item) + if itemlist[0].contentType == 'movie': + if not itemlist[0].server: + self.commands.append(itemlist[0].clone(action='add_pelicula_to_library', thumbnail=support.thumb('add_to_videolibrary'))) + self.commands.append(itemlist[0].clone(channel='downloads', action='save_download', from_channel=itemlist[0].channel, from_action=itemlist[0].action, thumbnail=support.thumb('downloads'))) + else: + self.commands.append(Info.clone(channel='downloads', action='save_download', from_channel=Info.channel, from_action=Info.action, thumbnail=support.thumb('downloads'))) + if itemlist[0].contentType in ['tvshow', 'episode']: + if not itemlist[0].server: + self.commands.append(itemlist[0].clone(action='add_serie_to_library', thumbnail=support.thumb('add_to_videolibrary'))) + self.commands.append(itemlist[0].clone(channel='downloads', action='save_download', from_channel=itemlist[0].channel, from_action=itemlist[0].action, thumbnail=support.thumb('downloads'))) + else: + self.commands.append(Info.clone(channel='downloads', action='save_download', from_channel=Info.channel, from_action=Info.action, thumbnail=support.thumb('downloads'))) - if not self.video_url: - platformtools.dialog_notification(config.get_localized_string(60507), config.get_localized_string(60508), 2) - self.close() - elif self.video_url == "no_video": - self.close() + if self.commands: + commands = [] + for command in self.commands: + it = xbmcgui.ListItem(command.title) + path = filetools.join(config.get_runtime_path(),'resources','skins','Default','media','Infoplus',command.thumbnail.split('/')[-1].replace('thumb_','')) + it.setProperty('thumbnail',path) + commands.append(it) + self.getControl(COMMANDS).addItems(commands) + if self.items: + self.getControl(FANART).setImage(self.items[0].getProperty('fanart')) + + self.getControl(RECOMANDED).addItems(self.items) + self.getControl(LOADING).setVisible(False) + getFocus(self) + + def onClick(self, control_id): + setFocus(self) + if control_id == COMMANDS: + from platformcode.launcher import run + pos = self.getControl(COMMANDS).getSelectedPosition() + if self.commands[pos].action =='save_download' and self.commands[pos].contentType == 'tvshow': + actions = [self.commands[-1].clone(), self.commands[-1].clone(download='season')] + options = [config.get_localized_string(60355),config.get_localized_string(60357)] + run(actions[platformtools.dialog_select(config.get_localized_string(60498),options)]) + else: + run(self.commands[pos]) else: - new_video = False - while True: - if new_video: self.doModal() - xlistitem = xbmcgui.ListItem(path=self.video_url, thumbnailImage=self.item.thumbnail) - pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) - pl.clear() - pl.add(self.video_url, xlistitem) - self.player = xbmc.Player() - self.player.play(pl, windowed=True) - while xbmc.Player().isPlaying(): xbmc.sleep(1000) + action = self.getControl(RECOMANDED).getSelectedItem().getProperty('action') + channel = self.getControl(RECOMANDED).getSelectedItem().getProperty('channel') + url = self.getControl(RECOMANDED).getSelectedItem().getProperty('url') + item = Item(channel=channel, action=action, url=url) + if action == 'play': + item.server = self.getControl(RECOMANDED).getSelectedItem().getProperty('server') self.close() - self.video_url = None - new_video = True - self.windows[-1].doModal() - try: - self.video_url = self.windows[-1].result - if not self.video_url: break - except: - break + platformtools.play_video(item) + xbmc.sleep(500) + while xbmc.Player().isPlaying(): + xbmc.sleep(500) + modal() + elif config.get_setting('autoplay'): + item.quality = self.getControl(RECOMANDED).getSelectedItem().getProperty('quality') + getattr(self.channel, item.action)(item) + self.close() + xbmc.sleep(500) + while xbmc.Player().isPlaying(): + xbmc.sleep(500) + modal() + else: + pos = self.getControl(RECOMANDED).getSelectedPosition() + self.close() + if self.itemlist[pos].mode: remove() + Search(self.itemlist[pos]) def onAction(self, action): - if action == ACTION_PREVIOUS_MENU or action == ACTION_GESTURE_SWIPE_LEFT or action == 110 or action == 92: - self.player.stop() + if self.getFocusId() in [RECOMANDED]: + fanart = self.getControl(self.getFocusId()).getSelectedItem().getProperty('fanart') + self.getControl(FANART).setImage(fanart) + action = action.getId() + if action in [BACKSPACE]: + self.close() + remove() + modal() + elif action in [EXIT]: self.close() - elif action == ACTION_MOVE_LEFT: xbmc.executebuiltin('PlayerControl(Rewind)') - elif action == ACTION_MOVE_RIGHT: xbmc.executebuiltin('PlayerControl(Forward)') - elif action == ACTION_SELECT_ITEM: xbmc.executebuiltin('PlayerControl(Play)') - elif action == 199 or action == ACTION_SHOW_FULLSCREEN or action == 9: xbmc.log("tuprimalafachaaa") - if action == 13: self.close() - -def get_recomendations(item, infoLabels, recommendations): - Type = item.contentType +def Trailer(info): + global info_list, trailers + trailers = [] + trailers_list = [] + Type = info.getProperty('mediatype') if Type != "movie": Type = "tv" - search = {'url': '%s/%s/recommendations' % (Type, infoLabels['tmdb_id']), 'language': def_lang, 'page': 1} - reco_tmdb = tmdb.Tmdb(discover=search, tipo=Type, idioma_Search=def_lang) + trailers_list = tmdb.Tmdb(id_Tmdb=info.getProperty('tmdb_id'), tipo=Type).get_videos() + if trailers_list: + for i, trailer in enumerate(trailers_list): + item = xbmcgui.ListItem(trailer['name']) + item.setProperties({'tile':trailer['name'], + 'url': trailer['url'], + 'thumbnail': 'http://img.youtube.com/vi/' + trailer['url'].split('=')[-1] + '/0.jpg', + 'fanart':info.getProperty('fanart'), + 'position':'%s/%s' % (i + 1, len(trailers_list))}) + trailers.append(item) + else: # TRY youtube search + patron = r'thumbnails":\[\{"url":"(https://i.ytimg.com/vi[^"]+).*?' + patron += r'text":"([^"]+).*?' + patron += r'simpleText":"[^"]+.*?simpleText":"([^"]+).*?' + patron += r'url":"([^"]+)' + matches = support.match('https://www.youtube.com/results?search_query=' + info.getProperty('title').replace(' ','+') + '+trailer+ita', patron = patron).matches + i = 0 + for thumb, title, text, url in matches: + i += 1 + item = xbmcgui.ListItem(title + ' - '+ text) + item.setProperties({'tile':title + ' - '+ text, 'url': url, 'thumbnail': thumb, 'fanart':info.getProperty('fanart'), 'position':'%s/%s' % (i, len(matches))}) + trailers.append(item) + main = TrailerWindow('TrailerWindow.xml', config.get_runtime_path()) + add({'class':main, 'info':trailers, 'id':RECOMANDED, TRAILERS:0}) + modal() - for i in range(0, len(reco_tmdb.results)): - Title = reco_tmdb.results[i].get("title", reco_tmdb.results[i].get("original_title", "")) - if not Title: Title = reco_tmdb.results[i].get("name", reco_tmdb.results[i].get("original_name", "")) - idtmdb = str(reco_tmdb.results[i].get("id")) - thumbnail = reco_tmdb.results[i].get("poster_path", "") - if thumbnail: thumbnail = 'http://image.tmdb.org/t/p/original' + thumbnail - recommendations.append([idtmdb, Title, thumbnail]) +class TrailerWindow(xbmcgui.WindowXMLDialog): + def __init__(self, *args, **kwargs): + self.ids = {} + + def onInit(self): + #### Compatibility with Kodi 18 #### + if config.get_platform(True)['num_version'] < 18: + self.setCoordinateResolution(2) + self.getControl(FANART).setImage(trailers[0].getProperty('fanart')) + self.getControl(NUMBER).setText(trailers[0].getProperty('position')) + self.getControl(TRAILERS).addItems(trailers) + self.setFocusId(TRAILERS) + getFocus(self) + + def onClick(self, control_id): + setFocus(self) + if control_id in [TRAILERS]: + selected = self.getControl(TRAILERS).getSelectedItem() + platformtools.play_video(Item(title=selected.getProperty('title'), action='play', url=selected.getProperty('url'), server='youtube')) + while not xbmc.Player().isPlaying(): + xbmc.sleep(100) + self.close() + while xbmc.Player().isPlaying(): + xbmc.sleep(100) + modal() + + def onAction(self, action): + if self.getFocusId() in [TRAILERS]: + self.ids[self.getFocusId()] = self.getControl(self.getFocusId()).getSelectedPosition() + fanart = self.getControl(TRAILERS).getSelectedItem().getProperty('fanart') + position = self.getControl(TRAILERS).getSelectedItem().getProperty('position') + self.getControl(FANART).setImage(fanart) + self.getControl(NUMBER).setText(position) + action = action.getId() + global info_list + if action in [BACKSPACE]: + self.close() + remove() + modal() + elif action in [EXIT]: + self.close() -def get_fonts(skin): - data_font = "" - fonts = {} - if "confluence" in skin or "estuary" in skin or "refocus" in skin: fonts = {"10": "font10", "12": "font12", "16": "font16", "24": "font24_title", "30": "font30"} - elif "aeonmq" in skin: fonts = {"10": "font_14", "12": "font_16", "16": "font_20", "24": "font_24", "30": "font_30"} - elif "madnox" in skin: fonts = {"10": "Font_Reg22", "12": "Font_Reg26", "16": "Font_Reg32", "24": "Font_Reg38", "30": "Font_ShowcaseMainLabel2_Caps"} +def get_recomendations(info): + recommendations = [info] + Type = info.getProperty('mediatype') + if Type != "movie": Type = "tv" + search = {'url': '%s/%s/recommendations' % (Type, info.getProperty('tmdb_id')), 'language': 'it', 'page': 1} + tmdb_res = tmdb.Tmdb(discover=search, tipo=Type, idioma_Search='it').results + for result in tmdb_res: + if Type == 'movie': + title = result.get("title", '') + original_title = result.get("original_title", "") + else: + title = result.get("name", '') + original_title = result.get("original_name", '') + thumbnail ='http://image.tmdb.org/t/p/w342' + result.get("poster_path", "") if result.get("poster_path", "") else imagepath(Type) + fanart = 'http://image.tmdb.org/t/p/original' + result.get("backdrop_path", "") if result.get("backdrop_path", "") else '' + item = xbmcgui.ListItem(title) + item.setProperties({'title': title, + 'original_title': original_title, + 'mediatype': info.getProperty('mediatype'), + 'tmdb_id': result.get('id', 0), + 'imdb_id': info.getProperty('imdb_id'), + 'rating': result.get('vote_average', 0), + 'plot': result.get('overview', ''), + 'year': result.get('release_date', '').split('-')[0], + 'thumbnail': thumbnail, + 'fanart': fanart}) + recommendations.append(item) + return recommendations - if not fonts: - from core import filetools - try: - data_font = filetools.read(xbmc.translatePath(filetools.join('special://skin/1080i', 'Font.xml')), "r") - except: - try: data_font = filetools.read(xbmc.translatePath(filetools.join('special://skin/720p', 'Font.xml')), "r") - except: pass - - if data_font: - fuentes = scrapertools.find_multiple_matches(data_font, r"