From 29a5b2569e0af104805428279bd1c2f603365c9d Mon Sep 17 00:00:00 2001 From: Alhaziel01 Date: Thu, 13 Jan 2022 13:02:01 +0100 Subject: [PATCH] - Chiusura finestra server dopo standby - Menu contestuale in finestra server - Piccoli fix deltabit e uqloads - Piccolo fix gestione viste - Fix gestione salva link --- core/item.py | 4 +- core/jsontools.py | 13 +++- platformcode/launcher.py | 2 +- platformcode/platformtools.py | 137 ++++++++++++++++++++-------------- servers/deltabit.py | 2 +- servers/uqload.py | 2 +- specials/kodfavorites.py | 5 ++ 7 files changed, 103 insertions(+), 62 deletions(-) diff --git a/core/item.py b/core/item.py index 73f0f928..38d93fd1 100644 --- a/core/item.py +++ b/core/item.py @@ -355,7 +355,7 @@ class Item(object): dump = "".encode("utf8") return str(urllib.quote(base64.b64encode(dump))) - def fromurl(self, url): + def fromurl(self, url, silent=False): """ Generate an item from a text string. The string can be created by the tourl () function or have the old format: plugin: //plugin.video.kod/? channel = ... (+ other parameters) @@ -369,7 +369,7 @@ class Item(object): decoded = False try: str_item = base64.b64decode(urllib.unquote(url)) - json_item = json.load(str_item, object_hook=self.toutf8) + json_item = json.load(str_item, object_hook=self.toutf8, silent=silent) if json_item is not None and len(json_item) > 0: self.__dict__.update(json_item) decoded = True diff --git a/core/jsontools.py b/core/jsontools.py index a17b8f91..1ca455fb 100644 --- a/core/jsontools.py +++ b/core/jsontools.py @@ -16,15 +16,22 @@ if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int def load(*args, **kwargs): + silent = False + if 'silent' in kwargs: + silent = kwargs['silent'] + kwargs.pop('silent') + if "object_hook" not in kwargs: kwargs["object_hook"] = to_utf8 try: value = json.loads(*args, **kwargs) except: - logger.error("**NOT** able to load the JSON") - logger.error(traceback.format_exc()) - logger.error('ERROR STACK ' + str(stack()[1][3])) + if not silent: + logger.error("**NOT** able to load the JSON") + logger.error(traceback.format_exc()) + if len(stack()) > 1: + logger.error('ERROR STACK {}'.format(stack()[2]) ) value = {} return value diff --git a/platformcode/launcher.py b/platformcode/launcher.py index 188ea5e3..c0179884 100644 --- a/platformcode/launcher.py +++ b/platformcode/launcher.py @@ -381,7 +381,7 @@ def actions(item): else: config.set_setting('install_trakt', True) - if len([s for s in itemlist if s.server]) > 0: + if len([s for s in itemlist if s.server]) > 0 and item.action in ['findvideos']: findvideos(item, itemlist) else: platformtools.render_items(itemlist, item) diff --git a/platformcode/platformtools.py b/platformcode/platformtools.py index 740dfae8..8a5ba54c 100644 --- a/platformcode/platformtools.py +++ b/platformcode/platformtools.py @@ -343,8 +343,6 @@ def render_items(itemlist, parent_item): item.folder = False if item.fanart == "": item.fanart = parent_item.fanart - if item.action == 'play' and thumb_type == 1 and not item.forcethumb: - item.thumbnail = config.get_online_server_thumb(item.server) icon_image = "DefaultFolder.png" if item.folder else "DefaultVideo.png" @@ -397,7 +395,6 @@ def render_items(itemlist, parent_item): r_list.sort(key=lambda it: it[0].itemlistPosition) - # from core.support import dbg;dbg() for item, item_url, listitem in r_list: dirItems.append(('{}?{}'.format(sys.argv[0], item_url), listitem, item.folder, len(r_list))) xbmcplugin.addDirectoryItems(_handle, dirItems) @@ -430,17 +427,17 @@ def viewmodeMonitor(): if get_window() == 'WINDOW_VIDEO_NAV': try: parent_info = xbmc.getInfoLabel('Container.FolderPath') - parent = Item().fromurl(parent_info) if 'plugin.video.kod' in parent_info: - first_item_url = xbmc.getInfoLabel('Container.ListItemAbsolute(1).FileNameAndPath') - if first_item_url: - item = Item().fromurl(first_item_url) - currentModeName = xbmc.getInfoLabel('Container.Viewmode') - currentMode = int(xbmcgui.Window(10025).getFocusId()) - # logger.debug('SAVE VIEW 1', currentMode, parent.action, item.action) - if 50 <= currentMode < 600 and parent.action != item.action: - content, Type = getCurrentView(item, parent) - defaultMode = int(config.get_setting('view_mode_%s' % content).split(',')[-1]) + parent = Item().fromurl(parent_info, silent=True) + item = Item().fromurl(xbmc.getInfoLabel('ListItem.FileNameAndPath'), silent=True) + currentModeName = xbmc.getInfoLabel('Container.Viewmode') + currentMode = int(xbmcgui.Window(10025).getFocusId()) + # logger.debug('SAVE VIEW 1', currentMode, parent.action, item.action) + if 50 <= currentMode < 600 and parent and parent.action != item.action: + content, Type = getCurrentView(item, parent) + view_mode_type = config.get_setting('view_mode_%s' % content) + if view_mode_type: + defaultMode = int(view_mode_type.split(',')[-1]) if content and currentMode != defaultMode: config.set_setting('view_mode_%s' % content, currentModeName + ', ' + str(currentMode)) # logger.debug('SAVE VIEW 2', defaultMode, '->', currentMode) @@ -455,11 +452,12 @@ def viewmodeMonitor(): def getCurrentView(item=None, parent_item=None): + if not item: item = Item() - # if not parent_item: - # logger.debug('ESCO') - # return None, None + if not parent_item: + logger.debug('ESCO') + return None, None parent_actions = ['peliculas', 'novedades', 'search', 'get_from_temp', 'newest', 'discover_list', 'new_search', 'channel_search'] @@ -491,7 +489,7 @@ def getCurrentView(item=None, parent_item=None): return 'season', 'tvshows' elif parent_item.action in ['getmainlist', '', 'getchanneltypes']: - return 'home', addons + return None, None elif parent_item.action in ['filterchannels']: return 'channels', addons @@ -622,39 +620,16 @@ def set_context_commands(item, item_url, parent_item, **kwargs): else: context_commands.append((command["title"], "RunPlugin(%s?%s)" % (sys.argv[0], item.clone(**command).tourl()))) # Do not add more predefined options if you are inside kodfavoritos - # if parent_item.channel == 'kodfavorites': - # return context_commands + if parent_item.channel == 'kodfavorites': + if config.dev_mode(): + context_commands.insert(0, ("item info", "Container.Update (%s?%s)" % (sys.argv[0], Item(action="itemInfo", parent=item.tojson()).tourl()))) + return context_commands # Options according to criteria, only if the item is not a tag, nor is it "Add to the video library", etc... if item.action and item.action not in ["add_pelicula_to_library", "add_serie_to_library", "buscartrailer", "actualizar_titulos"]: # Show information: if the item has a plot, we assume that it is a series, season, chapter or movie # if item.infoLabels['plot'] and (num_version_xbmc < 17.0 or item.contentType == 'season'): # context_commands.append((config.get_localized_string(60348), "Action(Info)")) - if item.channel != "videolibrary" and item.videolibrary != False and not item.disable_videolibrary: - # Add Series to the video library - if item.action in ["episodios", "get_episodios", "get_seasons"] and item.contentSerieName: - context_commands.append((config.get_localized_string(60352), "RunPlugin(%s?%s&%s)" % ( - sys.argv[0], item_url, 'action=add_serie_to_library&from_action=' + item.action))) - # Add Movie to Video Library - elif item.action in ["detail", "findvideos"] and item.contentType == 'movie' and item.contentTitle: - context_commands.append((config.get_localized_string(60353), "RunPlugin(%s?%s&%s)" % ( - sys.argv[0], item_url, 'action=add_pelicula_to_library&from_action=' + item.action))) - # Add to Video Library - elif item.action in ['check'] and item.contentTitle: - context_commands.append((config.get_localized_string(30161), "RunPlugin(%s?%s&%s)" % ( - sys.argv[0], item_url, 'action=add_to_library&from_action=' + item.action))) - - # Search trailer... - if (item.contentTitle and item.contentType in ['movie', 'tvshow']) or "buscar_trailer" in context: - context_commands.append((config.get_localized_string(60359), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, urllib.urlencode({ 'channel': "trailertools", 'action': "buscartrailer", 'search_title': item.contentTitle if item.contentTitle else item.fulltitle, 'contextual': True})))) - - # Add to kodfavoritos (My links) - if item.channel not in ["favorites", "videolibrary", "help", ""] and parent_item.channel != "kodfavorites": - context_commands.append( (config.get_localized_string(70557), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, urllib.urlencode({'channel': "kodfavorites", 'action': "addFavourite", 'from_channel': item.channel, 'from_action': item.action})))) - # Add to kodfavoritos - if parent_item.channel == 'globalsearch': - context_commands.append( (config.get_localized_string(30155), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, urllib.urlencode({'channel': "favorites", 'action': "addFavourite", 'from_channel': item.channel, 'from_action': item.action})))) - # InfoPlus if config.get_setting("infoplus"): #if item.infoLabels['tmdb_id'] or item.infoLabels['imdb_id'] or item.infoLabels['tvdb_id'] or \ @@ -662,8 +637,19 @@ def set_context_commands(item, item_url, parent_item, **kwargs): if item.infoLabels['tmdb_id'] or item.infoLabels['imdb_id'] or item.infoLabels['tvdb_id']: context_commands.append(("InfoPlus", "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, 'channel=infoplus&action=Main&from_channel=' + item.channel))) - # Search in other channels - if item.contentTitle and item.contentType in ['movie', 'tvshow'] and parent_item.channel not in ['search', 'globalsearch'] and item.action not in ['play']: #and parent_item.action != 'mainlist': + # Open in browser and previous menu + if parent_item.channel not in ["news", "channelselector", "downloads", "search"] and item.action != "mainlist": + context_commands.insert(1, (config.get_localized_string(70739), "Container.Update (%s?%s)" % (sys.argv[0], Item(action="open_browser", url=item.url).tourl()))) + + # Add to kodfavoritos (My links) + + if item.channel not in ["favorites", "videolibrary", "help", ""] and parent_item.channel != "favorites" and parent_item.from_channel != "kodfavorites": + context_commands.append( (config.get_localized_string(70557), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, urllib.urlencode({'channel': "kodfavorites", 'action': "addFavourite", 'from_channel': item.channel, 'from_action': item.action})))) + # Add to kodfavoritos + if parent_item.channel == 'globalsearch': + context_commands.append( (config.get_localized_string(30155), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, urllib.urlencode({'channel': "favorites", 'action': "addFavourite", 'from_channel': item.channel, 'from_action': item.action})))) + # Search in other channels + if item.contentTitle and item.contentType in ['movie', 'tvshow'] and parent_item.channel not in ['search', 'globalsearch'] and item.action not in ['play'] and parent_item.action != 'mainlist': # Search in other channels if item.contentSerieName != '': @@ -682,10 +668,16 @@ def set_context_commands(item, item_url, parent_item, **kwargs): context_commands.append((config.get_localized_string(60350), "Container.Refresh (%s?%s&%s)" % (sys.argv[0], item_url, urllib.urlencode({'channel': 'search', 'action': "from_context", 'from_channel': item.channel, 'contextual': True, 'text': item.wanted})))) context_commands.append( (config.get_localized_string(70561), "Container.Update (%s?%s&%s)" % (sys.argv[0], item_url, 'channel=search&action=from_context&search_type=list&page=1&list_type=%s/%s/similar' % (mediatype, item.infoLabels['tmdb_id'])))) - - # Open in browser and previous menu - if parent_item.channel not in ["news", "channelselector", "downloads", "search"] and item.action != "mainlist" and not parent_item.noMainMenu: - context_commands.append((config.get_localized_string(70739), "Container.Update (%s?%s)" % (sys.argv[0], Item(action="open_browser", url=item.url).tourl()))) + if item.channel != "videolibrary" and item.videolibrary != False and not item.disable_videolibrary: + # Add Series to the video library + if item.action in ["episodios", "get_episodios", "get_seasons"] and item.contentSerieName: + context_commands.append((config.get_localized_string(60352), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, 'action=add_serie_to_library&from_action=' + item.action))) + # Add Movie to Video Library + elif item.action in ["detail", "findvideos"] and item.contentType == 'movie' and item.contentTitle: + context_commands.append((config.get_localized_string(60353), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, 'action=add_pelicula_to_library&from_action=' + item.action))) + # Add to Video Library + elif item.action in ['check'] and item.contentTitle: + context_commands.append((config.get_localized_string(30161), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, 'action=add_to_library&from_action=' + item.action))) if not item.local and item.channel not in ["downloads", "filmontv", "search"] and item.server != 'torrent' and parent_item.action != 'mainlist' and config.get_setting('downloadenabled') and not item.disable_videolibrary: # Download movie @@ -706,6 +698,10 @@ def set_context_commands(item, item_url, parent_item, **kwargs): elif item.contentType == "season": context_commands.append((config.get_localized_string(60357), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, 'channel=downloads&action=save_download&download=season&from_channel=' + item.channel + '&from_action=' + item.action))) + # Search trailer... + if (item.contentTitle and item.contentType in ['movie', 'tvshow']) or "buscar_trailer" in context: + context_commands.append((config.get_localized_string(60359), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, urllib.urlencode({ 'channel': "trailertools", 'action': "buscartrailer", 'search_title': item.contentTitle if item.contentTitle else item.fulltitle, 'contextual': True})))) + if item.nextPage: context_commands.append((config.get_localized_string(70511), "RunPlugin(%s?%s&%s)" % (sys.argv[0], item_url, 'action=gotopage&real_action='+item.action))) if config.dev_mode(): @@ -977,8 +973,6 @@ def get_window(): def play_video(item, strm=False, force_direct=False, autoplay=False): - from core import httptools - logger.debug() logger.debug(item.tostring('\n')) @@ -996,6 +990,7 @@ def play_video(item, strm=False, force_direct=False, autoplay=False): # pass referer if item.referer: + from core import httptools httptools.default_headers['Referer'] = item.referer # Open the selection dialog to see the available options @@ -1038,7 +1033,8 @@ def play_video(item, strm=False, force_direct=False, autoplay=False): # headers['Host'] = domain # except: # logger.error('Failed to resolve hostname, fallback to normal dns') - mediaurl = mediaurl + '|' + urllib.urlencode(headers) + if not '|' in mediaurl: + mediaurl = mediaurl + '|' + urllib.urlencode(headers) # video information is obtained. xlistitem = xbmcgui.ListItem(item.title, path=item.url) @@ -1736,6 +1732,7 @@ def channelImport(channelId): return channel def serverWindow(item, itemlist): + from core import db LEFT = 1 RIGHT = 2 UP = 3 @@ -1744,6 +1741,8 @@ def serverWindow(item, itemlist): EXIT = 10 BACKSPACE = 92 + CONTEXT = 117 + class ServerWindow(xbmcgui.WindowXMLDialog): def start(self, item, itemlist): prevent_busy() @@ -1797,6 +1796,11 @@ def serverWindow(item, itemlist): self.setFocusId(100) # from core.support import dbg;dbg() + def onFocus(self, control): + if is_playing() and db['controls'].get('reopen', False): + self.close() + serverWindow(self.item, self.itemlist) + def onAction(self, action): action = action.getId() focus = self.getFocusId() @@ -1804,6 +1808,8 @@ def serverWindow(item, itemlist): self.setFocusId(100) elif action in [EXIT, BACKSPACE]: self.close() + if action in [CONTEXT]: + context(self) def onClick(self, control): if control == 100: @@ -1878,11 +1884,24 @@ def serverWindow(item, itemlist): else: it.setLabel2(videoitem.fulltitle) it.setArt({'thumb': videoitem.thumbnail}) + items.append(it) self.list.reset() self.list.addItems(items) self.setFocus(self.list) + def onFocus(self, control): + if is_playing() and db['controls'].get('reopen', False): + self.close() + serverWindow(self.item, self.itemlist) + + def onAction(self, action): + action = action.getId() + if action in [CONTEXT]: + context(self) + if action in [EXIT, BACKSPACE]: + self.close() + def onClick(self, control): if control == 6: self.selection = self.itemlist[self.list.getSelectedPosition()] @@ -1902,10 +1921,20 @@ def serverWindow(item, itemlist): run(self.actions[0]) + def context(self): + pos = self.list.getSelectedPosition() + parent = self.item + item = self.itemlist[pos] + commands = set_context_commands(item, item.tourl(), parent) + context = [c[0] for c in commands] + context_commands = [c[1].replace('Container.Refresh', 'RunPlugin').replace('Container.Update', 'RunPlugin') for c in commands] + index = xbmcgui.Dialog().contextmenu(context) + if index > 0: xbmc.executebuiltin(context_commands[index]) + + if itemlist: def monitor(itemlist): reopen = False - from core import db while not xbmc.Monitor().abortRequested(): if not is_playing(): if reopen: diff --git a/servers/deltabit.py b/servers/deltabit.py index b217ae0e..a3cb1f40 100644 --- a/servers/deltabit.py +++ b/servers/deltabit.py @@ -14,7 +14,7 @@ def test_video_exists(page_url): data = page.data.replace('"', "'") real_url = page.url - if "Not Found" in data or "File Does not Exist" in data: + if "Not Found" in data or "File Does not Exist" in data or "File doesn't exits" in data: return False, config.get_localized_string(70449) % "DeltaBit" return True, "" diff --git a/servers/uqload.py b/servers/uqload.py index 46ec18ce..d92dd590 100644 --- a/servers/uqload.py +++ b/servers/uqload.py @@ -30,7 +30,7 @@ def get_video_url(page_url, premium=False, user="", password="", video_password= matches = re.compile(patron, re.DOTALL).findall(data) for url in matches: - url = url+'|Referer='+page_url + # url = url+'|Referer='+page_url video_urls.append(["[uqload]", url]) return video_urls diff --git a/specials/kodfavorites.py b/specials/kodfavorites.py index cc7f7fdf..dc741160 100644 --- a/specials/kodfavorites.py +++ b/specials/kodfavorites.py @@ -224,6 +224,7 @@ def mostrar_perfil(item): for i_enlace, enlace in enumerate(alfav.user_favorites[i_perfil]['items']): it = Item().fromurl(enlace) + it.from_channel = 'kodfavorites' it.context = [ {'title': config.get_localized_string(70617), 'channel': item.channel, 'action': 'acciones_enlace', 'i_enlace': i_enlace, 'i_perfil': i_perfil} ] @@ -232,6 +233,10 @@ def mostrar_perfil(item): it.plot += '[CR]Url: ' + it.url if isinstance(it.url, str) else '...' if it.date_added != '': it.plot += '[CR]' + config.get_localized_string(70469) + ': ' + it.date_added + if it.server: + it.thumbnail = it.contentThumbnail + it.title += ' [{}]'.format(it.serverName) + # If it is not a url, nor does it have the system path, convert the path since it will have been copied from another device. # It would be more optimal if the conversion was done with an import menu, but at the moment it is controlled in run-time. if it.thumbnail and '://' not in it.thumbnail and not it.thumbnail.startswith(ruta_runtime):