Kodi Community Forum

Full Version: Kodi Leia subtitle dialog uses plugin directory items instead of filesystem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When you're watching a video and pause it to go to Subtitles > Browse for subtitle... and open the dialog, the dialog now shows the directory items that your add-on generates, instead of showing the device filesystem for you to browse for subtitle files.

On Kodi Krypton this error didn't happen, it always showed the filesystem as expected.

On my own add-on I can see that Kodi is invoking the add-on again, that's why the add-on is generating a directory. 
Isn't there a way to just tell Kodi to use the filesystem already for this Browse For Subtitles dialog, like it's supposed to? Kodi doesn't send any extra parameters in sys.argv that I can use to tell when it's doing this "subtitle browsing" invoking vs regular navigation invoking.
I also noticed that if I force the add-on to not generate any directory items at all, it shows the filesystem as expected. 
I tested this by detecting when the add-on is being invoked while xbmc.Player().isPlayingVideo() == 1.

However this is not a solution as I want to be able to have the video in the background (hitting "Back" while playing the video), so the video goes on the background and the add-on directory goes on the foreground and you can properly navigate its folders, which won't be possible to do if you don't generate any items if a video is playing.
This is still a problem and is probably a bug, I think items that are resolved inside the video plugin have their paths that lead into the plugin, so when the subtitle browsing code adds the path to the item (probably in here), that path will lead back into the plugin instead of the local filesystem as it's the plugin that will resolve the path into an actual stream, to be set with xbmcplugin.setResolvedUrl(...)
Anyway, I found a way to circumvent this problem by checking the current window ID on the entry point of my video plugin:

python:
# The window WINDOW_FULLSCREEN_VIDEO (12005) is only present while playing a video.
# If the plugin is being invoked while a video is playing, the current window ID will be WINDOW_FULLSCREEN_VIDEO
# and you cannot generate any directories from your plugin, or else the subtitle browser will show them instead
# of the local filesystem.

if xbmcgui.getCurrentWindowId() == 12005:
    return
    
# If the user hits "Back" while playing the video, the current window ID will change to WINDOW_VIDEO_NAV (10025). So with this or any other window IDs you can make the plugin menus/directories as usual:

(...)
xbmcplugin.addDirectoryItems(...)
xbmcplugin.endOfDirectory(...)
NOTE: if this code is outside of a function (like on global scope), the return statement will cause an error. Therefore instead of using return you need to do some other logic so that your script ends without adding any directory items and without ending the directory. Like using a bool variable to ignore adding directory items, something like that:
python:
shouldAddItems = (xbmcgui.getCurrentWindowId() != 12005) # Only add directory items if the window ID is *not* WINDOW_FULLSCREEN_VIDEO.
(...)
if shouldAddItems:
    xbmcplugin.addDirectoryItems(...)
    xbmcplugin.endOfDirectory(...)

So if you want your video streaming plugin to support local browsing of subtitles, you can use something like the above.

PS: the window IDs were taken from source file WindowIDs.h: https://github.com/xbmc/xbmc/blob/master...IDs.h#L160