Kodi Community Forum

Full Version: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it possible to directly retrieve the total number of seasons of one tv show?
For skins there is:
Code:
ListItem.Property(TotalSeasons)

Is there something simulair for JSON?
Not possible for now unless by calling VideoLibrary.GetSeasons.
jimk72 Wrote:Not sure if this is a bug but when I start a movie in xbmc the onplay gives player Id 1 and when I play music in xbmc it gives id of 0. Which works fine but if I am listening to music and call player.open and send movieid it returns an onplay with playerid 0 when actually it should be 1. Calling a getitem with player 0 returns error but getitem playerid 1 returns the movie info?
Clicking movie in xbmc when playing music switches playerid back to 1. My guess is calling player.open isn't switching the playerid properly.

After further testing I've also received a playerid of -1 from an onplay notification.

This commit should fix the problem for both media started through Player.Open and media started through recentlyadded: https://github.com/xbmc/xbmc/commit/5748...380a2e0807

But the media is still not added to the correct playlist but notifications now contain the correct playerid.
Montellese Wrote:Not possible for now unless by calling VideoLibrary.GetSeasons.

Is this something that could be included in the future (if yes should i create a request ticket) or just stick to the 'VideoLibrary.GetSeasons' ?

I have some problem retrieving the tvshow ID. All it returns is : none
What am I doing wrong in this code:
Code:
findtvshowid = re.search( '"tvshowid":"(.*?)","', mediaitem )

Complete code:
http://pastebin.com/cWHXQxSa

Log:
http://pastebin.com/ZZZnLKZ9
Machine-Sanctum Wrote:Is this something that could be included in the future (if yes should i create a request ticket) or just stick to the 'VideoLibrary.GetSeasons' ?

I'll have to see if it will increase the query retrieval time or not. Feel free to create a feature request ticket.

Quote:I have some problem retrieving the tvshow ID. All it returns is : none
What am I doing wrong in this code:
Code:
findtvshowid = re.search( '"tvshowid":"(.*?)","', mediaitem )

Complete code:
http://pastebin.com/cWHXQxSa

Log:
http://pastebin.com/ZZZnLKZ9

I still don't understand why you guys aren't usin JSON libraries. It makes using the data from the responses sooo much easier. In your case the regex is wrong because there are no double-quotes around an integer value. Furthermore most of your regexes will fail if someone disables compact JSON output through Advanced Settings (like I have to better debug).
Montellese Wrote:I'll have to see if it will increase the query retrieval time or not. Feel free to create a feature request ticket.
If it won't make things. I'll create a feature request ticket anyway.

Quote:I still don't understand why you guys aren't usin JSON libraries. It makes using the data from the responses sooo much easier. In your case the regex is wrong because there are no double-quotes around an integer value. Furthermore most of your regexes will fail if someone disables compact JSON output through Advanced Settings (like I have to better debug).
I removedd the double quote however this created another error.

You mean the way logo-downloader handles requests for how it should be coded?

Well I only started to learn python couple of weeks ago so it was the choice of the other guys. So i'm just learning as i go along and just expanding the existing code. Still little lost in all the python/JSON coding Blush
Machine-Sanctum Wrote:You mean the way logo-downloader handles requests?

Well I only started to learn python couple of weeks ago so it was the choice of the other guys. So i'm just learning as i go along and just expanding the existing code. Still little lost in all the python/JSON coding Blush

there's a simplejson script module in our addon repo that could/should be used instead of doing regex matches on the results.
i only found out about it last night (thanx pieh) :-)

like you, i used the existing scripts as an example when i started creating python addons....guess we've all been doing it wrong right from the start.
ronie Wrote:there's a simplejson script module in our addon repo that could/should be used instead of doing regex matches on the results.
i only found out about it last night (thanx pieh) :-)

like you, i used the existing scripts as an example when i started creating python addons....guess we've all been doing it wrong right from the start.

Well we took some of our code from the logo-downloader Laugh

What's it called and is there a readme/example included on how to use it?

Also found some cache handle script however there's no readme/examples included.
Machine-Sanctum Wrote:Well we took some of our code from the logo-downloader Laugh

What's it called and is there a readme/example included on how to use it?

script.module.simplejson/

PHP Code:
import simplejson
[...]
json_response xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "properties": ["playcount", "resume", "plot", "season", "episode", "showtitle", "thumbnail", "fanart", "file", "lastplayed"], "sort": { "method": "episode" }, "tvshowid":%s }, "id": 1}' tvshow)
jsonobject simplejson.loads(json_response)
if 
jsonobject['result'].has_key('items'):
    for 
item in jsonobject['result']['items']:
        if 
item.has_key('resume') and item['resume']['position'] > 0:
            
#mark this item as partially watched
            
item['partiallywatched'] = True
        playcount 
item['playcount']
        
#whatever goes here 

Machine-Sanctum Wrote:Also found some cache handle script however there's no readme/examples included.

and you want us to guess the name of the scipt?

count me in!
what's the first prize?
ronie Wrote:and you want us to guess the name of the scipt?

count me in!
what's the first prize?

Haha sorry forgot about that Big Grin
Could be wrong however maybe you can shed some light on what it actually does.
http://mirrors.xbmc.org/addons/eden-pre/...gin.cache/

Sorry for the off-topic.
EDIT:
Nevermind. Found it the previous problem.

Altough still have this problem:

Code:
if jsonobject_season['result'].has_key('limits'):
                    for item in jsonobject_season['result']['limits']:
                        Media["seasontotal"] = item['total']
                        Media["seasonstart"] = item['start']
                        Media["seasonend"] = item['end']
                        log('Season total: %s' %Media['seasontotal'])
                        log('Season start: %s' %Media['seasonstart'])
                        log('Season end: %s' %Media['seasonend'])
This error:
Code:
15:56:06 T:1108   ERROR: Traceback (most recent call last):
                                              File "D:\XBMC Eden\portable_data\addons\script.extrafanartdownloader\default.py", line 542, in <module>
                                                Main()
                                              File "D:\XBMC Eden\portable_data\addons\script.extrafanartdownloader\default.py", line 47, in __init__
                                                solo_mode(self, self.mediatype, self.medianame)
                                              File "D:\XBMC Eden\portable_data\addons\script.extrafanartdownloader\default.py", line 234, in solo_mode
                                                self.Medialist = Media_listing('TVShows')
                                              File "D:\XBMC Eden\portable_data\addons\script.extrafanartdownloader\resources\lib\media_setup.py", line 43, in media_listing
                                                Media["seasontotal"] = str(item['total'])
                                            TypeError: string indices must be integers
Machine-Sanctum Wrote:Altough still have this problem:

I tried several things, read some documentation however i'm to inexperienced to solve the problem above on my own Blush
The rest of it all function without a problem.
If some one could give a hand i would be grateful Nod
I don't really know python but from looking at the code this line doesn't make much sense to me:
Code:
for item in jsonobject_season['result']['limits']:
The "limits" object is not an array but an object so if you ran the "for in" operator the "item" variable will get the values of the properties inside "limits" and ends up being a string in which case something like
Code:
item['total']
isn't valid anymore. "item" is a string and you can only use integer-based indeces on strings (hence the error message).

Something like this might work
Code:
if jsonobject_season['result'].has_key('limits'):
                    limits = jsonobject_season['result']['limits']:
                    Media["seasontotal"] = limits['total']
                    Media["seasonstart"] = limits['start']
                    Media["seasonend"] = limits['end']
                    log('Season total: %s' %Media['seasontotal'])
                    log('Season start: %s' %Media['seasonstart'])
                    log('Season end: %s' %Media['seasonend'])
Montellese Wrote:I don't really know python but from looking at the code this line doesn't make much sense to me:

Well you know enough. It worked. Thanks Big Grin
Thanks for the update about the onplay!

I redid a lot and am now using http to get and post JSON. tcp seems fine to send json but when you recieve it(especially if getting entire artist list,4000+) it is so fragmented you have to do preparsing to make sure you have the entire request recieved.

Now using http I get the entire json for each singular request. Everything works perfect. Am also using superobject to parse the json.

I did have one request: does anyone know if there is a shortcut to get the image of a album that has no thumbnail, empty artist thumbnail, empty movie thumbnail? These are the images xbmc displays when no image is avail.

I know I could just find them in the source for xbmc but then I am using their images in my program. I would rather either load them through http from xbmc or instead of xbmc json returning "thumbnail":"" it could return the path to the default thumbnail xbmc uses.

Hope that wasnt to complicated.