Kodi Community Forum
JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Printable Version

+- Kodi Community Forum (http://forum.kodi.tv)
+-- Forum: Development (/forumdisplay.php?fid=32)
+--- Forum: Development (/forumdisplay.php?fid=93)
+---- Forum: JSON-RPC (/forumdisplay.php?fid=174)
+---- Thread: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC (/showthread.php?tid=68263)



- hans234567 - 2012-03-04 02:20

Ok, thanks for your fast reply.
Sorry for posting this question again, I will search better next time. Rolleyes


- samdret - 2012-03-04 09:41

Hello again Smile

Disclaimer: I'm using MySQL. (Ninja edit: and XBMC Eden b2)

I'm wondering if there's a way to get the current database revision (I think that's what you call it) number from XBMC via JSON RPC? My system would like a way to backup said database.

Also, I would love the ability to add sources via JSON RPC to the MySQL database. Or at the very least, directly into the XBMC databases. Previously I just edited sources.xml, but since going over to MySQL, this is no longer possible.

Any word on a screenshot feature for JSON RPC?

Would it also be a possibility to get a function which returns the appropriate ID (to use with Play) when given a filename?

Mark movies/episodes as "Watched" via JSON RPC?


- Montellese - 2012-03-04 09:53

samdret Wrote:I'm wondering if there's a way to get the current database revision (I think that's what you call it) number from XBMC via JSON RPC? My system would like a way to backup said database.
I don't think that this will ever make it into JSON-RPC because it offers zero benefit to a normal client which wants to access the libraries and control playback etc. Furthermore if you want to perform a backup you'll have to access the MySQL database manually anyway so why don't you do that in the first place and use some SQL queries to get the name of your database?

samdret Wrote:Also, I would love the ability to add sources via JSON RPC to the MySQL database. Or at the very least, directly into the XBMC databases. Previously I just edited sources.xml, but since going over to MySQL, this is no longer possible.
Sources are not stored in the database independant of whether you use MySQL or SQLite, they are still stored in a sources.xml. In the future there will eventually be the functionality to add/edit/remove sources but it's not one of the urgent features. Please create a feature request ticket for it.

samdret Wrote:Any word on a screenshot feature for JSON RPC?
Not yet. Please create a feature request ticket.

samdret Wrote:Would it also be a possibility to get a function which returns the appropriate ID (to use with Play) when given a filename?
Why don't you just pass the filename in the "file" property of the "item" parameter of Player.Open or Playlist.Add? Saves you a call to an extra function.

samdret Wrote:Mark movies/episodes as "Watched" via JSON RPC?
This will be possible with my FooLibrary.SetBarDetails() methods which should be available in the next release. You'll be able to set the "playcount" property to whatever you want.


- samdret - 2012-03-04 10:29

Montellese Wrote:I don't think that this will ever make it into JSON-RPC because it offers zero benefit to a normal client which wants to access the libraries and control playback etc. Furthermore if you want to perform a backup you'll have to access the MySQL database manually anyway so why don't you do that in the first place and use some SQL queries to get the name of your database?

Thanks, I guess that'll have to do Smile Edit: Found that I can just check %AppData%/Roaming/XBMC/userdata/Database/ and see which files are there. I.e. MyVideos18.db and MyVideos58.db which is the same name as the databases XBMC created.


Montellese Wrote:Sources are not stored in the database independant of whether you use MySQL or SQLite, they are still stored in a sources.xml. In the future there will eventually be the functionality to add/edit/remove sources but it's not one of the urgent features.

I can't believe I missed that. Must've been a brain freeze.


Montellese Wrote:Not yet. Please create a feature request ticket.

On it!


Montellese Wrote:Why don't you just pass the filename in the "file" property of the "item" parameter of Player.Open or Playlist.Add? Saves you a call to an extra function.

I believe I've tried this, but when it's done this way, Player.GetItem does not return all the meta data that XBMC has, only marginal information. I'll give this another go and report back.


Montellese Wrote:This will be possible with my FooLibrary.SetBarDetails() methods which should be available in the next release. You'll be able to set the "playcount" property to whatever you want.

Awesome. By next release, you mean RC3/Final or Eden+1?


- Montellese - 2012-03-04 10:58

samdret Wrote:I believe I've tried this, but when it's done this way, Player.GetItem does not return all the meta data that XBMC has, only marginal information. I'll give this another go and report back.
When you go through JSON-RPC with a file that is in XBMC's databases you should always get all the information available. If the file is not in the database you will only get a limited set of information. There will be some improvement for this in the future but not for Eden.

samdret Wrote:Awesome. By next release, you mean RC3/Final or Eden+1?
Beta's and RC's are not real releases. With "next release" I refer to Eden+1 i.e. Frodo.


- Millencolin007 - 2012-03-04 21:01

Hi, I just run into another problem with Files.PrepareDownload

I am trying to download the file from the following location on the disk of my xbmc. The filename contains + characters in the filename

/media/media/Music/Full Albums/Electro/Bob Sinclar feat. Sean Paul - Disco Crash - 2012/02 - Bob Sinclar feat. Sophie Ellis-Bextor & Gilbere Forte - F++k With You.mp3

As usual requesting the download url
Code:
curl -d "{\"jsonrpc\": \"2.0\", \"method\": \"Files.PrepareDownload\", \"params\" : { \"path\" : \"/media/media/Music/Full Albums/Electro/Bob Sinclar feat. Sean Paul - Disco Crash - 2012/02 - Bob Sinclar feat. Sophie Ellis-Bextor & Gilbere Forte - F++k With You.mp3\" }, \"id\" : 1 }" http://192.168.1.40:6666/jsonrpc

returns the json string with the download path

Code:
{"id":1,"jsonrpc":"2.0","result":{"details":{"path":"vfs/%2fmedia%2fmedia%2fMusic%2fFull%20Albums%2fElectro%2fBob%20Sinclar%20feat%2e%20S​ean%20Paul%20%2d%20Disco%20Crash%20%2d%202012%2f02%20%2d%20Bob%20Sinclar%20feat%​2e%20Sophie%20Ellis%2dBextor%20%26%20Gilbere%20Forte%20%2d%20F%2b%2bk%20With%20Y​ou%2emp3"},"mode":"redirect","protocol":"http"}}


Trying to download the file gives me a file not found exception
Code:
curl http://192.168.1.40:6666/vfs/%2fmedia%2fmedia%2fMusic%2fFull%20Albums%2fElectro%2fBob%20Sinclar%20feat%2e%20S​ean%20Paul%20%2d%20Disco%20Crash%20%2d%202012%2f02%20%2d%20Bob%20Sinclar%20feat%​2e%20Sophie%20Ellis%2dBextor%20%26%20Gilbere%20Forte%20%2d%20F%2b%2bk%20With%20Y​ou%2emp3

From the xbmc logs I can see that xbmc tried to open the file without a + sign in it.

Code:
ERROR: WebServer: Failed to open /media/media/Music/Full Albums/Electro/Bob Sinclar feat. Sean Paul - Disco Crash - 2012/02 - Bob Sinclar feat. Sophie Ellis-Bextor & Gilbere Forte - F  k With You.mp3

Am I doing something wrong or is this a bug in xbmc?


- Montellese - 2012-03-04 21:12

The problems is the two "+" you have in your path. XBMC thinks that "+" needs to be replaced with a whitespace when decoding the URL. I'll have to read up in the RFC on URI/URLs on how this is supposed to work. But it looks like XBMC correctly URL encodes the "+" to "%2b" but on decoding it it first decodes "%2b" to "+" and then to a whitespace.


- Millencolin007 - 2012-03-04 21:51

Montellese Wrote:The problems is the two "+" you have in your path. XBMC thinks that "+" needs to be replaced with a whitespace when decoding the URL. I'll have to read up in the RFC on URI/URLs on how this is supposed to work. But it looks like XBMC correctly URL encodes the "+" to "%2b" but on decoding it it first decodes "%2b" to "+" and then to a whitespace.

Yes, that is probably what is happening. I was able to download the file by encoding the %2b a second time to %252b so that the + sign stays after decoding

The working download url looks like this
Code:
http://192.168.1.40:6666/vfs/%2fmedia%2fmedia%2fMusic%2fFull%20Albums%2fElectro%2fBob%20Sinclar%20feat%2e%20S​ean%20Paul%20%2d%20Disco%20Crash%20%2d%202012%2f02%20%2d%20Bob%20Sinclar%20feat%​2e%20Sophie%20Ellis%2dBextor%20%26%20Gilbere%20Forte%20%2d%20F%252b%252bk%20With​%20You%2emp3



- Montellese - 2012-03-04 21:55

I have located the problem. It seems that the library we use for our webserver already decodes incoming URLs and then we (i.e. XBMC) decode it again so first the %2b is decoded to + by libmicrohttpd and then to a whitespace by XBMC. I'll see if I can get a fix for that into Eden.


- Millencolin007 - 2012-03-04 21:58

Montellese Wrote:I have located the problem. It seems that the library we use for our webserver already decodes incoming URLs and then we (i.e. XBMC) decode it again so first the %2b is decoded to + by libmicrohttpd and then to a whitespace by XBMC. I'll see if I can get a fix for that into Eden.

Great! Thanks for your help


- Montellese - 2012-03-04 22:05

Millencolin007 Wrote:Great! Thanks for your help

Fixed in https://github.com/xbmc/xbmc/commit/d5b351937a92d1dbc8976145f7a1078c54a087ad and thanks for reporting this.


- Millencolin007 - 2012-03-05 00:08

Sorry I'ts me once again ;-)

I am looking for a way to retrieve music playlists. Since there seems no way to do this through the api I was trying to get the playlists using Files.GetDirectory from special://musicplaylists like below and the parsing the files myself. Unfortunately the returned filetype is always "directory"

Request
Code:
curl -d "{\"jsonrpc\": \"2.0\", \"method\": \"Files.GetDirectory\", \"params\" : { \"directory\" : \"special://musicplaylists\" }, \"id\" : 1 }" http://192.168.1.40:6666/jsonrpc | python -mjson.tool

Response
Code:
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "files": [
            {
                "file": "special://profile/playlists/music/arabic.xsp",
                "filetype": "directory",
                "label": "arabic",
                "type": "unknown"
            },
            {
                "file": "special://profile/playlists/music/hip-hop.xsp",
                "filetype": "directory",
                "label": "hip-hop",
                "type": "unknown"
            },
            {
                "file": "special://profile/playlists/music/aaa.xsp",
                "filetype": "directory",
                "label": "pop-rock",
                "type": "unknown"
            },
            {
                "file": "special://profile/playlists/music/Queue.m3u",
                "filetype": "directory",
                "label": "Queue.m3u",
                "type": "unknown"
            },
            {
                "file": "special://profile/playlists/music/rhythmbox/",
                "filetype": "directory",
                "label": "rhythmbox",
                "type": "unknown"
            },
            {
                "file": "special://profile/playlists/music/salsa.xsp",
                "filetype": "directory",
                "label": "salsa",
                "type": "unknown"
            },
            {
                "file": "special://profile/playlists/music/test/",
                "filetype": "directory",
                "label": "test",
                "type": "unknown"
            }
        ],
        "limits": {
            "end": 7,
            "start": 0,
            "total": 7
        }
    }
}



- Montellese - 2012-03-05 00:11

Yeah that's intended and correct because to XBMC a smartplaylist is a directory/node containing items (e.g. movies, episodes, albums, songs, ...). So you pass one of those paths to an XSP to Files.GetDirectory and specify the matching "media" parameter ("music" in the above example) and you will get a list of all items contained in that playlist. You can even retrieve all the properties you'd get from AudioLibrary.GetFoo if you specify them in the "properties" parameter.


- Millencolin007 - 2012-03-05 00:20

Montellese Wrote:Yeah that's intended and correct because to XBMC a smartplaylist is a directory/node containing items (e.g. movies, episodes, albums, songs, ...). So you pass one of those paths to an XSP to Files.GetDirectory and specify the matching "media" parameter ("music" in the above example) and you will get a list of all items contained in that playlist. You can even retrieve all the properties you'd get from AudioLibrary.GetFoo if you specify them in the "properties" parameter.

Nice! Thanks a lot.


- jimk72 - 2012-03-05 19:24

I have noticed when testing xbmc side by side with my program that the thumb for currently playing songs isn't always sent. It's always the same songs. Does xbmc research the net if a thumb is not in the database? It will show the album cover in xbmc but when using json to get the data it returns blank. This is a small percentage of my songs. There are a few others that show the generic music icon in xbmc and nothing is sent as expected. Just figured if xbmc is displaying a image for a song that it would send it.