Solved Query the database for beginners
#1
Hi, new guy here.

How do I go about getting the data I want from the kodi database?
Would you provide a working example of how to get data from the database?


I cannot get the built-in stuff to do list items the way I want to. I specifically plan to get the "artist dbid" from the database using the "artist name" so I can show a list of albums by a certain artist.
If it is possible to run the - assuming - script in an onclick event that should suffice nicely.

I see a lot of extras or addons around but what exactly they do or how to work with them or skin them I dont know. I think maybe I must learn som python and something about json? I dont need internet access ot parsing. Just a way to make better queries and returns than those provided.

I will be forever grateful if you can get me started!! Cool

I apologize if you think this is common knowledge or easy to find in the wiki or has been answered a million times or wrong forum. I have vb, html, unity, xml experience and can "skin" the xml.
Reply
#2
Can you explain what you'd like to do with the data once you've got it? The more detail you give us the more helpful we can make our replies.

And, yes, using json is likely to be the way to go here.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#3
Hi, thanks for the question.

I want to show a list of albums in a skin just like it is possible already

I think all I need is to lookup the artist name in the artist table and return the artist dbid. I just need this single value returned.

What I want to achieve is similar to using the content tag in a panel list showing albums by a specific artist. Filled with the path musicdb://artist/[artistDBID]. This functionality is.already present but I cannot get the artist dbid from the panel of albums which is where I need to get it from. I want this panel list with albums next to a panel with other albums. I have all of it working sort of nicely except for getting the darn artist dbid or album artist dbid(looking forward to the onclick in panels filled by path).

How would i run this json magic? Assume i am Jon Snow here ;-)
Reply
#4
have a look at the globalsearch addon:
https://github.com/ronie/script.globalse...ui.py#L526
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#5
Looks readable-ish. Now what? Is all scrioting called addons and are all addons scripts? I can probably hack the oython in notepad, but then what? Where do i put it and such?
Reply
#6
you'll have to create an addon indeed.

if you're new to creating addons, have a look at this post:
160975 (thread)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#7
I will have a look. Shold my focus be on plugin or script? http://kodi.wiki/index.php?title=Python_...us_scripts
Reply
#8
since you want to have 2 panels on the screen at the same time (correct me if i'm wrong), it needs to be a script.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#9
II do. At least two:-) I already have two panels and a list with no issues. All I need is the albumartist dbid to be able to fill one of the panels correctly. In fact all skinning is ready and satisfactory using the build in options.

By using the content tag it seems we can have all the panels we want and they wont suddenly show odd content decided by some secret black-box überboss functionality.

. (Sorry for spelling. Smartphone and fat fingers)
Reply
#10
I am confused. Can an addon script return just a single value to a variable or a list to a panel upon request in an onclick event? Or how does it work?

Edit:Yes.. yes it can:

In the your_addon.py:

WINDOW = xbmcgui.Window( 10000 )
WINDOW.setProperty( 'PropToSet' , 'pass this string' )

And in the skin:
$INFO[Window(Home).Property(PropToSet)
Reply
#11
How do I fix this to return an artist if the variable abumDBID is matched?

json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": {"properties": ["artist"], "filter": {"field": "idAlbum", "operator": "equals", "value":"%s"} }, "id": 1}' % ALBUMDBID)

json_query = unicode(json_query, 'utf-8', errors='ignore')

json_response = json.loads(json_query)

If I send the response to Kodi I can see there is an error saying it did not find a match! So something is wrong with.. something.. Big Grin

(I amongst everything don't understand what the %s is all about)

Thank you VERY much for you time! Smile

More info

I call these lines after defining the query above:

if json_response.has_key('result') and (json_response['result'] != None) and json_response['result'].has_key('artist'):
WINDOW.setProperty( 'dbLookParamFound' , 'I FOUND IT' )

There seems to be no response from json as the window property never gets set to "I FOUND IT".

The json is probably simplejson.

There are no errors in the log.

The ALBUMDBID is from sys.argv[1] and the number is a valid number gotten from the album listing in a Kodi skin.

As you can see I got a wee bit further towards making my own queries in the databases and have been able to pass values from Kodi to python and back thrugh a .script in an addon. So far so good..But this whole json scriptamagicky is weirder than grasping the 11th dimension.. or learing chinese.. or understanding my gf.. Wink
Reply
#12
(continued from post above)

How to get album information?

json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbumDetails", "params": {"albumid": {"Library.Id": %d} }, "id": 1 }' % 33)

This fails miserably. I am an idiot.. Please help! I tried looking at http://kodi.wiki/view/JSON-RPC_API/v6#Au....GetAlbums but I have no clue what I look at really.......

What is it you want to do again?

I want to go from an Album list to a list of related albums. First up is the albums matching the artist. For that I simply need the artist DBID, and I cannot get that from the album list as it is NOT being provided. So, I plan to get the album info, to get the album artist name, to get the dbid, to get the album list.. or something. For now I just need to get something, then the details will follow.. I hope.. Future dreams: Get a decent list of relevant albums in collection for all albums by mixing from artist, genre+year and so on..
Reply
#13
Strike the above.. I got it I think:
json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbumDetails", "params": {"albumid": %d}, "id": 1 }' % int(ALBUMDBID))

But any hints are most welcomed!! Smile FML right Wink
Reply
#14
I got a bit further, leading to a new question:

How do I get a particular value from the returned info

This:
json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbumDetails", "params": {"albumid": %d, "properties": ["artistid"]}, "id": 1 }' % int(ALBUMDBID))

Returns the artistid in an array. I need the first item only (there will only ever be one I think?)
Reply
#15
And there it it..

json_response['result']['albumdetails']['artistid'][0] returns the first entry.

Seems like I got myself a discography Smile

Thanks for watching, hope you enjoyed the show.....
Reply

Logout Mark Read Team Forum Stats Members Help
Query the database for beginners0