Defining callback function for context menu items


I’m trying to build my first add-on which involves scraping a website and getting video information. I’d like to be able to define a callback function for when the user clicks the “Information” item in the default context menu to bring up the information dialog.

An example scenario is this: in my add-on I want to include a search function which returns a directory of list items. This functionality mimics the same functionality of the website for which I am building the add-on. On the website, the search results include a collection of video items, however by default this only includes basic information like title, media type, year, etc. A separate API call is required per search result to get additional information, such as the plot.

I want to minimise API calls and only make such a call if the user goes to the information dialog. Does such functionality exist? Is there a similar way to achieve my goal? I’ve done a lot of searching and unfortunately I can’t find any solution, just a lot of people being disappointed that they can’t adjust the context menu items. However, I’m sure this kind of behaviour is possible – I’m almost certain I’ve seen this kind of behaviour in practice before but I’m still a novice Kodi user so can’t find any examples of it now.

To be clear, I am aware of the addContextMenuItems function, I don’t think this will be able to assist me as it doesn’t change the behaviour of the built-in context menu items from what I can tell.