Hello,
I’m trying to achieve a Related videos custom menu action from a list item with addContextMenuItems and RunPlugin but I cannot make it work and I don’t understand the issue.
Basicaly I display a list of videos in listitems and for each I add a custom menu for related videos with addContextMenuItems and RunPlugin.
The context menu appears correctly but when I select it nothing happens, I expect to display another list of videos related on the current listitem.
For testing purpose I added a related list item that displays the related videos using the same plugin url and it works, so the issue should be in RunPlugin or something I missed but I cannot find what
python:def list_videos(genre_index):
"""
Create the list of playable videos in the Kodi interface.
:param genre_index: the index of genre in the list of movie genres
:type genre_index: int
"""
genre_info = get_videos(genre_index)
# Set plugin category. It is displayed in some skins as the name
# of the current section.
xbmcplugin.setPluginCategory(HANDLE, genre_info['genre'])
# Set plugin content. It allows Kodi to select appropriate views
# for this type of content.
xbmcplugin.setContent(HANDLE, 'movies')
# Get the list of videos in the category.
videos = genre_info['movies']
# Iterate through videos.
for video in videos:
# Create a list item with a text label
list_item = xbmcgui.ListItem(label=video['title'])
# Set graphics (thumbnail, fanart, banner, poster, landscape etc.) for the list item.
# Here we use only poster for simplicity's sake.
# In a real-life plugin you may need to set multiple image types.
list_item.setArt({'poster': video['poster']})
# Set additional info for the list item via InfoTag.
# 'mediatype' is needed for skin to display info for this ListItem correctly.
info_tag = list_item.getVideoInfoTag()
info_tag.setMediaType('movie')
info_tag.setTitle(video['title'])
# Set 'IsPlayable' property to 'true'. This is mandatory for playable items!
list_item.setProperty('IsPlayable', 'true')
# add a related ContextMenu with the URL
list_item.addContextMenuItems([ ("Show related...", "RunPlugin({})".format(get_url(action='related', genre_index=genre_index))) ])
# Create a URL for a plugin recursive call.
# Example: plugin://plugin.video.example/?action=play&video=https%3A%2F%2Fia600702.us.archive.org%2F3%2Fitems%2Firon_mask%2Firon_mask_512kb.mp4
url = get_url(action='play', video=video['url'])
# Add the list item to a virtual Kodi folder.
# is_folder = False means that this item won't open any sub-list.
is_folder = False
# Add our item to the Kodi virtual folder listing.
xbmcplugin.addDirectoryItem(HANDLE, url, list_item, is_folder)
# Add a Related list item with the same url for debug
list_item = xbmcgui.ListItem(label="Related")
rel_url = get_url(action='related', genre_index=genre_index)
xbmcplugin.addDirectoryItem(HANDLE, rel_url, list_item, False)
# Add sort methods for the virtual folder items
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(HANDLE)