ListItem.FileNameAndPath not working
#1
I'm trying to write my first KODI plugin (something similar to favorites) and so far so good except for 1 thing.

I have been stuck on this for a few days now, I simply can't figure out how to get the URL of a movie in the script that is called from a Context Menu item.

My addon.xml has this in it:

Code:
<extension point="kodi.context.item" library="capture.py">        
      <item>
        <label>Add to Shortlist</label>
        <visible>Container.Content(movies)</visible>
      </item>
    </extension>

And the capture.py script gets called no problem.

The main part of capture.py looks like this:

Code:
if __name__ == '__main__':    
    videoInfoTag = sys.listitem.getVideoInfoTag()
    
    item = ShortlistItem()
    item.title = sys.listitem.getLabel()
    item.duration = sys.listitem.getduration()
    item.rating = videoInfoTag.getRating()
    item.year = videoInfoTag.getYear()
    item.date = videoInfoTag.getPremiered()
    item.thumb = sys.listitem.getArt( 'thumb' )
    item.poster = sys.listitem.getArt( 'poster' )    

    addToShortlist( item )

Which all works great... but how do I get the URL of the movie so I can use it again later when I create a DirectoryItem?

I've been Googling non stop with little success.. I found a lot of references here on the forums to ListItem.FileNameAndPath but that doesn't seem to exist anymore, I found that mostly in older posts.

I think I'm missing something really obvious here, can anyone help?

Thanks in advance Smile
Reply
#2
Solved it, I was getting to hung up on working with ListItem and VideoInfoTag and totally missed the obvious:

Code:
filename = xbmc.getInfoLabel('ListItem.FilenameAndPath')
Reply
#3
Actually not solved :-(

While I'm getting a filename, it seems to be a totally random one from my library, not related to the item the context menu was called on.

videoInfoTag.getFile() return blank
videoInfoTag.getPath() works but no filename of course
listItem.getPath() shows something like: videodb://recentlyaddedmovies/14
listItem.getfilename() shows something like: videodb://recentlyaddedmovies/14

I've tried everything I can think of to get the filename to combine with the path, can anyone help?
Reply
#4
Since I'm having a conversation with myself, I'll just finish this off.

Code:
filename = xbmc.getInfoLabel('ListItem.FilenameAndPath')

Works OK if you are not using a mouse. If you use the mouse, the pointer can end up selecting a different item BEFORE the script runs, resulting in the wrong file.

With a normal remote this can happen too but you have to hit the left / right / up / down button really fast after selecting the context menu, far less likely to happen here.

I checked a few other addons that have context menu options to add an existing item (like SuperFavourites) and they all suffer from the same issue (In SuperFavourites I was able to get it to add the movie on the right of the one I had called the context menu on by just moving my mouse to the right immediately after clicking the context menu).

Guess this is just how it works, it wouldn't make sense to lock the KODI UI while the script is running.

Would be great if the listItem that is available after calling a context menu as sys.listitem contained the original URL / filename, that would fix this issue.
Reply
#5
The problem is that when you launch addon from context menu at first kodi closes context menu and returns focus to parent window, next starts yours addon. But before your command xbmc.getInfoLabel will executed python interpreter must load modules (import ...). For this need time too. All that time kodi interface was not locked and if you move mouse you change current listitem. Command xbmc.getInfoLabel('ListItem.FilenameAndPath') return value for current listitem. Thus when you moving mouse during addon launching you will get value for current listitem at moment when python interpreter execute getInfoLabel command.
You can try that method for partial solution:


import xbmc
currentItemPos = lambda : int( xbmc.getInfoLabel('Container.CurrentItem') )
i = currentItemPos()
#...
#import other modules
#...
getLi = lambda infolabel, idx=currentItemPos() : xbmc.getInfoLabel('ListitemNoWrap(%s).%s' % (str(idx-currentItemPos()), infolabel))
link = getLi (i, 'FilenameAndPath')
link = getLi ('FilenameAndPath', i)


this method gets you ability for getting any infolabels for any items
Reply
#6
Thanks, that's a neat way to do it.

Had to change last line to:
Code:
link = getLi ('FilenameAndPath', i)

Wink
Reply
#7
Yes, it's true. I'm sorry ))) confused Wink
Reply

Logout Mark Read Team Forum Stats Members Help
ListItem.FileNameAndPath not working0