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.
Jason102 Wrote:Has the functionality of the Files.GetDirectory call changed? I use the call in PseudoTV to get all of the elements in a smart playlist. This no longer works, I only receive an empty list using the daily builds:

Code:
{"id":1,"jsonrpc":"2.0","result":{"files":null,"limits":{"end":0,"start":0,"total":0}}}

Is this expected? Is there some new way to get smart playlist contents?

Montellese Wrote:You were right and I fixed it in this commit. Thanks for the report.

Am I missing something here? I'm trying to get the contents of a smart playlist but can't do it with Files.GetDirectory.

Using Files.GetDirectory on "special://videoplaylists" correctly lists my smart playlist (xsp) and a static one (m3u).

Using GetDirectory on the m3u file lists the files, but doing:
Code:
{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "special://profile/playlists/video/test.xsp"}, "id": 1}
just returns
Code:
{"id":1,"jsonrpc":"2.0","result":{"files":null,"limits":{"end":0,"start":0,"total":0}}}

any help would be greatly appreciated.

I'm using the nightly from 26 November.

Thanks,

el_P
el_Paraguayo Wrote:Am I missing something here? I'm trying to get the contents of a smart playlist but can't do it with Files.GetDirectory.

Using Files.GetDirectory on "special://videoplaylists" correctly lists my smart playlist (xsp) and a static one (m3u).

Using GetDirectory on the m3u file lists the files, but doing:
Code:
{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "special://profile/playlists/video/test.xsp"}, "id": 1}
just returns
Code:
{"id":1,"jsonrpc":"2.0","result":{"files":null,"limits":{"end":0,"start":0,"total":0}}}

any help would be greatly appreciated.

I'm using the nightly from 26 November.

Have you tried passing the "media" parameter as well? It is required for JSON-RPC to be able to access the correct database (audio or video). So try passing "media": "video" alongside the "directory" parameter and let me know if that fixes your problem.
Montellese Wrote:Have you tried passing the "media" parameter as well? It is required for JSON-RPC to be able to access the correct database (audio or video). So try passing "media": "video" alongside the "directory" parameter and let me know if that fixes your problem.

Ridiculously fast response Montellese!!

Works perfectly, thank you.
el_Paraguayo Wrote:Ridiculously fast response Montellese!!

Works perfectly, thank you.

Glad to hear that. You got lucky I just got the email notification Wink
Also meant to ask, is there a "random" sort order?

I'm updating a script that plays random movies and, at present, the random selection is done by the Python script which means the entire movie library is loaded into a list and then selects one at random.

If the JSON can output a random movie then this would make my job simpler.
Quick question: When I was parsing the playlist files and extracting items and sending them to xbmc through json it does not work when I send local files?

example:

smb://FREENAS/Music/AC_DC/AC_DC Live/Thunderstruck.mp3
adds to playlist fine but local files from a m3u file do not?

H:\Music\3 Doors Down\When You're Young\When You're Young.mp3

gives an error about incorrect params?

These are both from the same m3u file.

Just figured out I can get the files from a playlist through json and local files are as follows:
H:\\Music\\3 Doors Down\\When You're Young\\When You're Young.mp3

is this the format I need to send to add local files to playlist?
el_Paraguayo Wrote:Also meant to ask, is there a "random" sort order?

I'm updating a script that plays random movies and, at present, the random selection is done by the Python script which means the entire movie library is loaded into a list and then selects one at random.

If the JSON can output a random movie then this would make my job simpler.

Databases don't support random ordering so XBMC would have to implement it manually is well which means XBMC would have to retrieve all movies as well and then randomly sort them which is almost the same as when you have to do it in your script.
jimk72 Wrote:Quick question: When I was parsing the playlist files and extracting items and sending them to xbmc through json it does not work when I send local files?

example:

smb://FREENAS/Music/AC_DC/AC_DC Live/Thunderstruck.mp3
adds to playlist fine but local files from a m3u file do not?

H:\Music\3 Doors Down\When You're Young\When You're Young.mp3

gives an error about incorrect params?

These are both from the same m3u file.

Just figured out I can get the files from a playlist through json and local files are as follows:
H:\\Music\\3 Doors Down\\When You're Young\\When You're Young.mp3

is this the format I need to send to add local files to playlist?

The double backslash is needed in JSON because a backslash is an escape character (e.g. to escape double-quotes (") within a string) so you have to escape the backslash with another backslash. If you don't do that the JSON parser tries to interprete \M, \3 and \W (in the specific case of the path you posted) as special characters which will end up with an invalid path.
Montellese Wrote:Databases don't support random ordering so XBMC would have to implement it manually is well which means XBMC would have to retrieve all movies as well and then randomly sort them which is almost the same as when you have to do it in your script.

SQLLite or Mysql support random sorting very well Smile

And both with the same syntax :

PHP Code:
ORDER BY RAND() 
Montellese Wrote:Databases don't support random ordering so XBMC would have to implement it manually is well which means XBMC would have to retrieve all movies as well and then randomly sort them which is almost the same as when you have to do it in your script.

That's fine. I just wanted to check I wasn't doing something that could be done by adding an extra parameter to my request!
Tolriq Wrote:SQLLite or Mysql support random sorting very well Smile

And both with the same syntax :

PHP Code:
ORDER BY RAND() 

I didn't mean SQLite or MySQL but our VideoDatabase and MusicDatabase but I can see that my statement was not very well phrased. We don't do the sorting through SQL because in many cases it isn't that easily possible (for example when "ignorearticle" is used) so if we want to provide a random sort we'll have to implement it manually as well.
Montellese Wrote:The double backslash is needed in JSON because a backslash is an escape character (e.g. to escape double-quotes (") within a string) so you have to escape the backslash with another backslash. If you don't do that the JSON parser tries to interprete \M, \3 and \W (in the specific case of the path you posted) as special characters which will end up with an invalid path.

That was it! All playlists are selectable/viewable and playable now without any custom parsing from remote! I also noticed my smart playlists that have random will return a random order of the selected songs!

You guys are doing one hellofa job!! Im amazed at how fast it works. Most playlists are instantly loaded with zero delay.
I'm confused about how to use Player.Open. I checked the wiki but it just says "mixed" for the parameters. I introspected and I saw that there's a path parameter to Player.Open, and I am trying to use it like so..

Code:
{"params": {"path": "smb://192.168.0.200/path/to/my/file.avi"}, "jsonrpc": "2.0", "method": "Player.Open"}

Doesn't seem to work and doesn't give any JSON response. Also doesn't log anything in the debug log at level 2. Player.Open takes a "path" argument, does that replace the former "file" argument of XBMC.Play? I feel like I'm missing something obvious...

EDIT : Hey, jimk72's post below me answers my question! I guess it takes a Playlist.Item object.. which makes sense! yay!
Might have bug.

If I use
{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"special://profile/playlists/music/playlist.m3u"}},"id":1}
It loads into the playlistid 1? the playlist contains only 3 songs.
but if I do
{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"special://profile/playlists/music/playlist.xsp"}},"id":1}

A smart playlist of only songs, It loads it into playlistid 0.

Getplaylists displays:
{"id":3,"jsonrpc":"2.0","result":[{"playlistid":0,"type":"audio"},{"playlistid":1,"type":"video"},{"playlistid":2,"type":"picture"}]}

Active player returns:
{"id":1,"jsonrpc":"2.0","result":[{"playerid":0,"type":"audio"}]}
for both of the above.

There is no way to tell if playlist 1 or playlist 0 is playing? Which you need to know if you want to use playlist.add
jimk72 Wrote:Might have bug.

If I use
{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"special://profile/playlists/music/playlist.m3u"}},"id":1}
It loads into the playlistid 1? the playlist contains only 3 songs.
but if I do
{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"special://profile/playlists/music/playlist.xsp"}},"id":1}

A smart playlist of only songs, It loads it into playlistid 0.

Getplaylists displays:
{"id":3,"jsonrpc":"2.0","result":[{"playlistid":0,"type":"audio"},{"playlistid":1,"type":"video"},{"playlistid":2,"type":"picture"}]}

Active player returns:
{"id":1,"jsonrpc":"2.0","result":[{"playerid":0,"type":"audio"}]}
for both of the above.

There is no way to tell if playlist 1 or playlist 0 is playing? Which you need to know if you want to use playlist.add

It's not really a bug because that's how XBMC works. If it has to create a playlist from multiple files it (by default) creates a video playlist unless there is some specific meta data that can be retrieved that specifies it as a music playlist (which is possible with smart playlists). This logic/implementation is far from perfect and I don't really know why it is done this way but that's how it is.

If you want to know the playlistid of the playlist used by a player you can use Player.GetProperties and retrieve the "playlistid" property.