How to make Kodi load different folder programmatically?
#1
I am pretty sure this should be possible in Kodi but I just can't figure out how. Here is my scenario...

I have a search function which takes a user search string and then builds builds a result set and displays it as a directory. Context menu commands allow for things like item deletion, adding/removing as favourites, etc. After executing any of the context commands a Container.Refresh is required. The problem is that the refresh doesn't just reload the result set, it also asks the user for the search string again.

My intended solution is to break the search into two addon reloads. First, choosing "Search" from the top-level menu would load a new folder, say "searchquery", and the code for that folder uses xmbc.Keyboard to ask for the search string. If the user doesn't cancel then the code for the "searchquery" folder should build a new URL which loads a second folder, say "search", just as if that second folder had been the action URL of a directory item. My thinking is that this way after the result set is displayed calling Container.Refresh will only reload the folder using the arguments passed to it from the "searchquery" folder code.

My problem is that I just can't figure out how to make Kodi change folders this way without actually using a directory list item the user has to click on. I can call the URL with executebuiltin('RunPlugin()') but that doesn't actually make Kodi completely change to another folder so the result set gets loaded but not displayed.

What am I missing?
Reply
#2
as far as i can follow this i would recommend 2 functions as you seem to have eluded to

1 function when the addon is called which shows the input box to get the search term (when query is empty or unset)

1 function which will display listitems when called with "plugin://plugin.yourplugin/?query=searchquery"

then when Container.Refresh is called, the Container path will be "plugin://plugin.yourplugin/?query=searchquery" and it will reload the results for the query instead of requesting a new query
Reply
#3
Thanks for the response. I came up with a solution for my situation which might not be applicable for everyone. Since I posted this question I also implemented search history in a SQLite database so now I save the current search term in the database when entered and then let Kodi load plugin://plugin.myplugin/?mode=searchresults which reads the current search term from the database and retrieves the result. If I first clear the current search term in the database then my plugin://plugin.myplugin/?mode=searchresults knows to ask for it in a dialog instead. After the user confirms the new term it gets saved as the current search term database (and also to the history list) so that calling Container.Refresh finds the search term there the second time so doesn't ask for it again. Alternatively if the user picks one of the remembered search terms from the history list that gets saved to the database as the current search term so plugin://plugin.myplugin/?mode=searchresults retrieves the results for that search term.

The way Kody addons work it's difficult to explain what I'm doing in concise language but I hope this description is clear enough. It basically works the same as the search screen in the official YouTube addon now.
Reply
#4
(2023-09-25, 15:31)arsMOBILIS Wrote: The way Kody addons work it's difficult to explain what I'm doing in concise language but I hope this description is clear enough.

makes perfect sense to me, sounds like it works
Reply
#5
(2023-09-25, 15:31)arsMOBILIS Wrote: Thanks for the response. I came up with a solution for my situation which might not be applicable for everyone. Since I posted this question I also implemented search history in a SQLite database so now I save the current search term in the database when entered and then let Kodi load plugin://plugin.myplugin/?mode=searchresults which reads the current search term from the database and retrieves the result. If I first clear the current search term in the database then my plugin://plugin.myplugin/?mode=searchresults knows to ask for it in a dialog instead. After the user confirms the new term it gets saved as the current search term database (and also to the history list) so that calling Container.Refresh finds the search term there the second time so doesn't ask for it again. Alternatively if the user picks one of the remembered search terms from the history list that gets saved to the database as the current search term so plugin://plugin.myplugin/?mode=searchresults retrieves the results for that search term.

The way Kody addons work it's difficult to explain what I'm doing in concise language but I hope this description is clear enough. It basically works the same as the search screen in the official YouTube addon now.

I didn't think of this approach when you initially asked but after seeing your solution, it is almost identical to how I manage UPnP servers in my addon.  I keep a saved list of servers which pops up automatically, unless no servers have ever been saved.  The user can select a server they have used previously or choose to refresh the list (i.e. find a new server etc..).  I find users really like this vs. having to go back to a previous state manually.   Although I am a huge SQLite fan, I used pickle and my addion settings for this list save.  One day I will convert it over to SQLite.

Nice solution you came up with.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply

Logout Mark Read Team Forum Stats Members Help
How to make Kodi load different folder programmatically?0