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

+- XBMC Community Forum (http://forum.xbmc.org)
+-- 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)



- jimk72 - 2011-11-29 04:31

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?


- Montellese - 2011-11-29 10:20

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.


- Montellese - 2011-11-29 10:22

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.


- Tolriq - 2011-11-29 10:54

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() 



- el_Paraguayo - 2011-11-29 11:11

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!


- Montellese - 2011-11-29 12:06

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.


- jimk72 - 2011-11-29 17:23

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.


- darwin - 2011-11-30 00:46

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!


- jimk72 - 2011-11-30 02:24

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


- Montellese - 2011-11-30 09:51

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.