def generic_menu(plugin, **kwargs): """ Build a generic addon menu with all not hidden items """ plugin.redirect_single_item = True menu_id = kwargs.get('item_id') menu = get_sorted_menu(plugin, menu_id) if not menu: # If the selected menu is empty just reload the current menu yield False for index, (item_order, item_id, item_infos) in enumerate(menu): item = Listitem() # Set item label item.label = get_item_label(item_id) # Set item art if 'thumb' in item_infos: item.art["thumb"] = common.get_item_media_path(item_infos['thumb']) if 'fanart' in item_infos: item.art["fanart"] = common.get_item_media_path( item_infos['fanart']) # Set item params # If this item requires a module to work, get # the module path to be loaded if 'module' in item_infos: item.params['item_module'] = item_infos['module'] item.params['item_id'] = item_id item.params['item_dict'] = item2dict(item) # Get the next action to trigger if this # item will be selected by the user item_callback = eval(item_infos['callback']) item.set_callback(item_callback) add_context_menus_to_item(plugin, item, index, menu_id, len(menu), item_infos=item_infos) yield item
def generic_menu(plugin, menu_id, item_module=None, item_dict=None): """ Build a generic addon menu with all not hidden items """ # TEMPO (waiting for the CodeQuick update) plugin.cache_to_disc = True menu = get_sorted_menu(menu_id) if not menu: # If the selected menu is empty just reload the current menu yield False for index, (item_order, item_id, item_infos) in enumerate(menu): item = Listitem() add_context_menus_to_item(plugin, item, index, item_id, menu_id, len(menu)) label = LABELS[item_id] if isinstance(label, int): label = plugin.localize(label) item.label = label # Get item path of icon and fanart if 'thumb' in item_infos: item.art["thumb"] = common.get_item_media_path(item_infos['thumb']) if 'fanart' in item_infos: item.art["fanart"] = common.get_item_media_path( item_infos['fanart']) # If this item requires a module to work, get # the module path to be loaded item.params['item_module'] = item_infos.get('module') # Get the next action to trigger if this # item will be selected by the user item.set_callback(eval(item_infos['callback']), item_id, item_dict=cqu.item2dict(item)) yield item
def add_item_to_favourites(plugin, item_dict={}, **kwargs): """ Callback function called when the user click on 'add item to favourite' from an item context menu """ if 'channel_infos' in kwargs and \ kwargs['channel_infos'] is not None: # This item come from tv_guide_menu # We need to remove guide TV related # elements item_id = item_dict['params']['item_id'] label = item_id if item_id in LABELS: label = LABELS[item_id] if isinstance(label, int): label = Script.localize(label) item_dict['label'] = label if 'thumb' in kwargs['channel_infos']: item_dict['art']["thumb"] = common.get_item_media_path( kwargs['channel_infos']['thumb']) if 'fanart' in kwargs['channel_infos']: item_dict['art']["fanart"] = common.get_item_media_path( kwargs['channel_infos']['fanart']) item_dict['info'] = {} # Extract the callback item_path = xbmc.getInfoLabel('ListItem.Path') item_dict['callback'] = item_path.replace( 'plugin://plugin.video.catchuptvandmore', '') s = mem_storage.MemStorage('fav') prefix = '' try: prefix = s['prefix'] except KeyError: pass label_proposal = item_dict['label'] if prefix != '': label_proposal = prefix + ' - ' + label_proposal # Ask the user to edit the label item_dict['label'] = utils.keyboard( plugin.localize(LABELS['Favorite name']), label_proposal) # If user aborded do not add this item to favourite if item_dict['label'] == '': return False # Add this item to favourite db with storage.PersistentDict("favourites.pickle") as db: # Compute hash value used as key in the DB item_hash = md5(str(item_dict)).hexdigest() item_dict['params']['order'] = len(db) db[item_hash] = item_dict Script.notify(Script.localize(30033), Script.localize(30805), display_time=7000)
def tv_guide_menu(plugin, **kwargs): # Move up and move down action only work with this sort method plugin.add_sort_methods(xbmcplugin.SORT_METHOD_UNSORTED) menu_id = kwargs.get('item_id') menu = get_sorted_menu(plugin, menu_id) channels_id = [] for index, (channel_order, channel_id, channel_infos) in enumerate(menu): channels_id.append(channel_id) # Load the graber module accroding to the country # (e.g. resources.lib.channels.tv_guides.fr_live) tv_guide_module_path = 'resources.lib.channels.tv_guides.' + menu_id tv_guide_module = importlib.import_module(tv_guide_module_path) # For each channel grab the current program according to the current time tv_guide = tv_guide_module.grab_tv_guide(channels_id) for index, (channel_order, channel_id, channel_infos) in enumerate(menu): item = Listitem() # Set item label item.label = get_item_label(channel_id) # Set item art if 'thumb' in channel_infos: item.art["thumb"] = common.get_item_media_path( channel_infos['thumb']) if 'fanart' in channel_infos: item.art["fanart"] = common.get_item_media_path( channel_infos['fanart']) # If this item requires a module to work, get # the module path to be loaded if 'module' in channel_infos: item.params['item_module'] = channel_infos['module'] # If we have program infos from the grabber if channel_id in tv_guide: guide_infos = tv_guide[channel_id] if 'title' in guide_infos: item.label = item.label + ' — ' + guide_infos['title'] item.info['originaltitle'] = guide_infos.get('originaltitle') # e.g Divertissement, Documentaire, Film, ... item.info['genre'] = guide_infos.get('genre') plot = [] if 'specific_genre' in guide_infos: if 'genre' not in guide_infos: item.info['genre'] = guide_infos['specific_genre'] elif guide_infos.get('genre') in guide_infos['specific_genre']: item.info['genre'] = guide_infos['specific_genre'] else: plot.append(guide_infos['specific_genre']) # start_time and stop_time must be a string if 'start_time' in guide_infos and 'stop_time' in guide_infos: plot.append(guide_infos['start_time'] + ' - ' + guide_infos['stop_time']) elif 'start_time' in guide_infos: plot.append(guide_infos['start_time']) if 'subtitle' in guide_infos: plot.append(guide_infos['subtitle']) if 'plot' in guide_infos: plot.append(guide_infos['plot']) item.info['plot'] = '\n'.join(plot) item.info['episode'] = guide_infos.get('episode') item.info['season'] = guide_infos.get('season') item.info["rating"] = guide_infos.get('rating') item.info["duration"] = guide_infos.get('duration') if 'fanart' in guide_infos: item.art["fanart"] = guide_infos['fanart'] if 'thumb' in guide_infos: item.art["thumb"] = guide_infos['thumb'] item.params['item_id'] = channel_id item.params['item_dict'] = item2dict(item) # Get the next action to trigger if this # item will be selected by the user item.set_callback(eval(channel_infos['callback'])) add_context_menus_to_item(plugin, item, index, menu_id, len(menu), is_playable=True, channel_infos=channel_infos) yield item
def tv_guide_menu(plugin, **kwargs): # Move up and move down action only work with this sort method plugin.add_sort_methods(xbmcplugin.SORT_METHOD_UNSORTED) # Get sorted menu of this live TV country menu_id = kwargs.get('item_id') menu = get_sorted_menu(plugin, menu_id) try: # Load xmltv module xmltv = importlib.import_module('resources.lib.xmltv') # Get tv_guide of this country tv_guide = xmltv.grab_tv_guide(menu_id, menu) except Exception as e: Script.notify(Script.localize(LABELS['TV guide']), Script.localize( LABELS['An error occurred while getting TV guide']), display_time=7000) Script.log('xmltv module failed with error: {}'.format( e, lvl=Script.ERROR)) tv_guide = {} for index, (channel_order, channel_id, channel_infos) in enumerate(menu): item = Listitem() # Set item label item.label = get_item_label(channel_id) # Set item art if 'thumb' in channel_infos: item.art["thumb"] = common.get_item_media_path( channel_infos['thumb']) if 'fanart' in channel_infos: item.art["fanart"] = common.get_item_media_path( channel_infos['fanart']) # If this item requires a module to work, get # the module path to be loaded if 'module' in channel_infos: item.params['item_module'] = channel_infos['module'] # If we have program infos from the grabber if 'xmltv_id' in channel_infos and channel_infos[ 'xmltv_id'] in tv_guide: guide_infos = tv_guide[channel_infos['xmltv_id']] # Title if 'title' in guide_infos: item.label = item.label + ' — ' + guide_infos['title'] # Credits credits = [] for credit, l in guide_infos.get('credits', {}).items(): for s in l: credits.append(s) item.info['credits'] = credits # Country if 'country' in guide_infos: item.info['country'] = guide_infos['country'] # Category if 'category' in guide_infos: item.info['genre'] = guide_infos['category'] # Plot plot = [] # start_time and stop_time must be a string if 'start' in guide_infos and 'stop' in guide_infos: s = guide_infos['start'] + ' - ' + guide_infos['stop'] plot.append(s) elif 'stop' in guide_infos: plot.append(guide_infos['stop']) if 'sub-title' in guide_infos: plot.append(guide_infos['sub-title']) if 'desc' in guide_infos: plot.append(guide_infos['desc']) item.info['plot'] = '\n'.join(plot) # Duration item.info["duration"] = guide_infos.get('length') # Art if 'icon' in guide_infos: item.art["thumb"] = guide_infos['icon'] item.params['item_id'] = channel_id item.params['item_dict'] = item2dict(item) # Get the next action to trigger if this # item will be selected by the user item.set_callback(eval(channel_infos['callback'])) add_context_menus_to_item(plugin, item, index, menu_id, len(menu), is_playable=True, channel_infos=channel_infos) yield item