how to get ListItem object by name or path in python
#1
Hi. I am a Beginner in python. I try to learn from other scripts.

I have a movie title and the path from my DB. example "Starship Troopers".

I try:
titel='Starship Trooper'
url = 'c:\Movies\Starship_Trooper.mp4'
liz1=xbmcgui.ListItem(label=titel)
liz2 = xbmcgui.ListItem(path=url) 
Now looks like
liz1 "<xbmcgui.ListItem object at 0x118C7Bc0>"
liz2 "<xbmcgui.ListItem object at 0x118C7Bcc>"
But the ListItem.DBID in my DB is 494 from Starship Troopers. strangely ??
So, I Dont understand. I have set the ListItem to 494?
I want to use ListItem.Trailer or ListItem.Plot? example xbmc.executebuiltin('PlayMedia($ESCINFO[ListItem.Trailer])')
I have see something like:
ListItem = liz
And then they can use it.
But 0x118C7Bc0.Plot can not run. I know.

How do I tell the script that ListItem relates to a Movie with label or path?

thank you
Reply
#2
Hi,

so you seem to have a few misunderstandings there 
Quote:liz1=xbmcgui.ListItem(label=titel)
liz2 = xbmcgui.ListItem(path=url) 
this generates two new objects of type ListItem one with your url and one with the label. This is not a lookup you make two new list items.
Quote:liz1 "<xbmcgui.ListItem object at 0x118C7Bc0>"
liz2 "<xbmcgui.ListItem object at 0x118C7Bcc>"
this is python saying liz1 is an object of the ListItem class stored at memory index 0x118C7Bc0. This is absolutly unimportant for you and pure python internal. DON'T use these memory indexes EVER! They will change every time.
There is quite a few things more to this but this is a bit much to explain all of this in a thread. Do a python tutorial do get the basic stuff.
If you want to inspect your objects just to see what attribs they have you can use the dir(<yourobject>).
Quote:But the ListItem.DBID in my DB is 494 from Starship Troopers. strangely ??
So, I Dont understand. I have set the ListItem to 494?
Nope. The DBID is given by kodi. What you can do (mind you that's my limited experience with the kodi api there are maybe better ways) is use json rpcs Files.GetDirectory with path videodb://movies/<DBID> and than construct a listitem from this info.
or alternatively something like this which is the copy paste from a skin which does searches
videodb://tvshows/titles/-1/-1/-1/-1/?xsp=%7B%22order%22%3A%7B%22direction%22%3A%22ascending%22%2C%22ignorefolders%22%3A0%2C%22method%22%3A%22sorttitle%22%7D%2C%22rules%22%3A%7B%22and%22%3A%5B%7B%22field%22%3A%22title%22%2C%22operator%22%3A%22contains%22%2C%22value%22%3A%5B%22$INFO[Skin.String(CustomSearchTerm)]%22%5D%7D%5D%7D%2C%22type%22%3A%22episodes%22%7D
you have to lookup the structure of that xsp list thing pretty sure it's somewhere in the wiki explained

what exactly do you want to achieve? your explanation is really wild.
Reply
#3
Hi Takezo36. Thank you for answer. 
you: your explanation is really wild. 
Yes.  Laugh  I know. 
Ok. From the beginning. I want to open a script. I type in the Titel from the Movie. Und The script play the Trailer. what all i wont.
My problem is to understand how i open my database. here: https://kodi.wiki/view/InfoLabels stand by ListItem.Label -> Shows the left label of the currently selected item in a container.
so i have to select the item. listitem i think. 
example Then i open the xml DialogVideoinfo.xml i am in the container, and i can use listitem.xxx what i want. 
so how can i select the container / item / listitem in python? i want to use like xbmc.executebuiltin('PlayMedia($ESCINFO[ListItem.Trailer])') .
for use the listitem.xxx order i have to be inside the corect container. now i understnad, but not how.
win = xbmcgui.Window(xbmcgui.getCurrentWindowId())?

is that here what i want? https://forum.kodi.tv/showthread.php?tid...pid2471532
wid = xbmcgui.getCurrentWindowId()
win = xbmcgui.Window(wid)
cid = win.getFocusId()
control = win.getFocus()
listitem = control.getSelectedItem()

in my script listitem is "None" so i am not in an WindowID? where  I am? Huh
thank you
Reply
#4
(2020-05-14, 19:04)Michael_ger_krauts Wrote: Hi Takezo36. Thank you for answer. 
you: your explanation is really wild. 
Yes.  Laugh  I know. 
Ok. From the beginning. I want to open a script. I type in the Titel from the Movie. Und The script play the Trailer. what all i wont.
My problem is to understand how i open my database. here: https://kodi.wiki/view/InfoLabels stand by ListItem.Label -> Shows the left label of the currently selected item in a container.
so i have to select the item. listitem i think. 
example Then i open the xml DialogVideoinfo.xml i am in the container, and i can use listitem.xxx what i want. 
so how can i select the container / item / listitem in python? i want to use like xbmc.executebuiltin('PlayMedia($ESCINFO[ListItem.Trailer])') .
for use the listitem.xxx order i have to be inside the corect container. now i understnad, but not how.
win = xbmcgui.Window(xbmcgui.getCurrentWindowId())?

is that here what i want? https://forum.kodi.tv/showthread.php?tid...pid2471532
wid = xbmcgui.getCurrentWindowId()
win = xbmcgui.Window(wid)
cid = win.getFocusId()
control = win.getFocus()
listitem = control.getSelectedItem()

in my script listitem is "None" so i am not in an WindowID? where  I am? Huh
thank you

OK. you took a bit of a wrong turn there.
As ronie under that post says this does only work for windows generated from a plugin itself. So these classes are meant to build your own window from a plugin. Some windows (don't ask me why) don't have an id.
Anyways so you want to click a button open the keyboard and than use the input to search and play the first results trailer?
So call your plugin then bring up the keyboard 
https://codedocs.xyz/xbmc/xbmc/group__py...board.html
get the input from there in your plugin
than this is were it gets more complicated... and i haven't played with this part very much so only roughly speaking here...
kodi has smart playlist ... which are basically a filter to videosdb queries
https://kodi.wiki/view/Smart_playlists
the previous example url decoded looks like that 
videodb://tvshows/titles/-1/-1/-1/-1/?xsp={"order":{"direction":"ascending","ignorefolders":0,"method":"sorttitle"},"rules":{"and":[{"field":"title","operator":"contains","value":["SEARCHTERM"]}]},"type":"episodes"}  ,  this is for kodi a folder you can get via xbmcvfs or json rpc call Files.GetDirectory.
My intepretation which might be wrong of this is 
videodb://tvshows/titles/-1/-1/-1/-1/?xsp means videosdb://<tvshow/movie>/<in titles>/<in all titles>/<in all seasons>/<in all episodes> use this smart playlist


There is an existing search the database plugin https://kodi.wiki/view/Add-on:Global_Search which you might want to have a look at as insperation how to do the actual search part
https://gitlab.com/ronie/script.globalsearch/
Reply
#5
OK nevermind the whole smart playlist stuff... looking at ronies code you shoud be able to do all with json rpc calls 
there is a rule part in VideoLibrary.getmovies which allows you to search. He does quite some string replacement but the basic gist is 
'method':'VideoLibrary.GetMovies', 'properties':MOVIELABELS, 'sort':'title', 'rule':'"filter":{"field":"title", "operator":"contains", "value":"<YOUR TERM>"}', 
put that into a jsonrpc call pass this via executejsonrpc 
https://kodi.wiki/view/JSON-RPC_API/v8

here is a working example of a json rpc call using simplejson to load the data in dict (see how you can now just go through the result by indexing temp['result'])
  command = '{"jsonrpc": "2.0","method": "Player.GetItem","params": {"playerid": 1, "properties":["director","setid"]}, "id": 1}'
  temp = json.loads(xbmc.executeJSONRPC(command))
  if('result' in temp):
    return temp['result']
  return None

put the right method there and put all the other things into the params part
Reply
#6
{'jsonrpc': '2.0', 'method': 'VideoLibrary.GetMovies', 'params': { 'properties': [ 'trailer' ] }, 'id': 'libMovies'}

Yes! Takezo36! You are the best.  After your post  i found this.  https://forum.kodi.tv/showthread.php?tid...pid2457133
now i know wtf is 'jsonrpc'.  https://kodi.wiki/view/JSON-RPC_API/v6#V...vieDetails 16. -> [ Optional.String trailer = null ]. I think with  'params': { 'properties': [ 'trailer' ] }, i ask for "ListItem.Trailer" Path. Or?
Why "VideoLibrary.GetMoviesDetails" not run, i don t no. 
You think you known the code? Yes. I experiment with "Random Movie" Addon. Now i can Play Random Trailer.  Laugh   And i understand a litle how they solved the problem to open the Kodi DB with Python.

I just have to discover how do  make a loop in Python.  Rolleyes But it s make fun to learn. 

Thank You Takezo36!
Reply
#7
found it
n = 2
i = 0
bla ...
bla ... generiert (movie['trailer']
bla ...
while i <= n:
  while xbmc.Player().isPlaying():
    xbmc.sleep(10) -> https://forum.kodi.tv/showthread.php?tid...pid2692087 <- Takezo36 who else
 xbmc.executebuiltin('PlayMedia(%s)'%(movie['trailer']))
 i = i +1
Reply
#8
the lop is poopoo. 
i have change it to dialog.yesno: the original is from https://kodi.tv/addon/program-add-ons-sc...ndom-movie pdnagilum
Now its play random trailer from own kodi-database.

#settings.xml:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings> 
  <category label="32001">
    <setting label="ab Jahr"  type="number" id="jahr" default="2000" />
  </category>
</settings>



#addon.py:
import xbmc,xbmcaddon,xbmcgui,json,random

def getAllMovies():
  rpccmd = {'jsonrpc': '2.0', 'method': 'VideoLibrary.GetMovies', 'params': { 'filter': { "or":[ {'field': 'year', 'operator': 'greaterthan', 'value': jahr }, {'field': 'year', 'operator': 'is', 'value': jahr }]},  'properties': [ 'trailer', 'file'  ] }, 'id': 'libMovies'}
#greatherthan and or is the year
  rpccmd = json.dumps(rpccmd)
  result = xbmc.executeJSONRPC(rpccmd)
  result = json.loads(result)
  return result
  

i=0
time   = 5000
addon     = xbmcaddon.Addon()
addonName = "Trailer Play"
addonIcon = addon.getAddonInfo('icon')
jahr = addon.getSetting('jahr')
dialog = xbmcgui.Dialog()
sekunden = 10

while i < 1:
    movies = getAllMovies()
    movie  = random.choice(movies['result']['movies'])        
    xbmc.executebuiltin('Notification(%s, %s %s, %d, %s)'%(addonName,"Trailer :",movie['label'],sekunden * 3000,addonIcon))
    xbmc.executebuiltin('PlayMedia(%s)'%(movie['trailer']))
    xbmc.sleep(time) #my kodi need time to start the trailer video
    while xbmc.Player().isPlaying():
            xbmc.sleep(time) # waiting the end of playing video
           #how can i close the script then i stop  playing video? It shouldn't ask me for next video.


    
    if dialog.yesno("Naechster Trailer startet in %s sec" % sekunden, "Moechtest du stoppen?", yeslabel = "Ja verdammt!", nolabel = "Noch ein Trailer", autoclose=int(sekunden * 1000)):
        i=2 #not the best way to ending the loop, but its run.  Blush
#You can definitely improve a lot.  
#I don't know the meaning of some things.
#I didn't succeed to open the movie['file'] with xbmc.executebuiltin('activatewindow(filemanager, "file")') or similar my files are in davs:// maybe this is the problemm
#it would be better to open the "file" with a jump to DianlogVideoinfo.xml. but I don't know how. maybe  with 'label'. Also I couldn't get the movieDBID​​​​​​​ with json. Huh if I need it at?
 
Reply

Logout Mark Read Team Forum Stats Members Help
how to get ListItem object by name or path in python0