2010-12-03, 06:35
I am rewriting part of my script to use the 'xbmc.executeJSONRPC' in order to make it work with any database setups(MySQL, SQLite and any other possible formats) I'm having some problems parsing the feed back.
the JSONRPC feed back is as follows:
the xbmc.log shows the following:
the problem appears as the following: if the "thumbnail": is missing, I can not parse the albumname...
Any and all help is appreciated!
Code:
def retrieve_album_list( self ):
print "# Retrieving Album List"
album_list = []
total = 0
json_album = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "id": 1}')
print json_album
json_albums = re.compile( "{(.*?)}", re.DOTALL ).findall(json_album)
for i in json_albums:
album = {}
id = re.search( '"albumid" : (.*?),', i )
if id:
albumid = (id.group(1))
print "Album ID: %s" % albumid
title = re.search( '"label" : "(.*?)",',i)
if title:
albumtitle = (title.group(1))
print "Album: %s" % repr(albumtitle)
else:
albumtitle = ""
if albumtitle == "":
pass
else:
total=total + 1
album["title"]=albumtitle
album["local_id"]= albumid
album_list.append(album)
#print album_list
#print "total: %s" % total
return album_list, total
the JSONRPC feed back is as follows:
Code:
21:15:46 T:2716855152 M:2611576832 NOTICE: {
"id" : 1,
"jsonrpc" : "2.0",
"result" : {
"albums" : [
{
"albumid" : 1,
"label" : "Black Jesuz"
},
{
"albumid" : 2,
"label" : "Greatests Hits - CD 1",
"thumbnail" : "special://masterprofile/Thumbnails/Music/8/82abf61a.tbn"
},
{
"albumid" : 3,
"label" : "Greatests Hits - CD 2",
"thumbnail" : "special://masterprofile/Thumbnails/Music/5/59bc5e8d.tbn"
},
the xbmc.log shows the following:
Code:
21:15:47 T:2716855152 M:2612072448 NOTICE: Album ID: 1
21:15:47 T:2716855152 M:2612072448 NOTICE: Album ID: 2
21:15:47 T:2716855152 M:2612072448 NOTICE: Album: 'Greatests Hits - CD 1'
21:15:47 T:2716855152 M:2612072448 NOTICE: Album ID: 3
21:15:47 T:2716855152 M:2612072448 NOTICE: Album: 'Greatests Hits - CD 2'
the problem appears as the following: if the "thumbnail": is missing, I can not parse the albumname...
Any and all help is appreciated!