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

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



Sorting on GetAlbums, GetArtists - ncarthy - 2011-01-13

I had also noticed that GetAlbums does the limit first, then the sorting. That is to say, if you specify start 0 and end 10 with sort ascending then it returns the first 10 albums it finds in the database and then sorts them. Those 10 albums are sorted by albumid I think. This behaviour can be demonstrated by doing a second query with a start of 10, end of 20 and comparing the results. It won't be the next 10 albums in alphabetical order.

GetArtists does it correctly, but at the very high cost of querying the database for ALL artists, then sorting and applying the limit.

Neither way is right... in an ideal world the sorting/limiting should be done by the database, not the libjson code. But that would require changes to the database code, outside of libjsonrpc.

This also leads to an inconsistency in the "total" parameter returned by libjsonrpc: For GetAlbums with start 0 and end 10 it will return 10, for GetArtists it will return the number of Artists in the database. I opened a Trac ticket for the totals problem in September (http://trac.xbmc.org/ticket/10146)


- litemotiv - 2011-01-13

ncarthy Wrote:I had also noticed that GetAlbums does the limit first, then the sorting. That is to say, if you specify start 0 and end 10 with sort ascending then it returns the first 10 albums it finds in the database and then sorts them. Those 10 albums are sorted by albumid I think. This behaviour can be demonstrated by doing a second query with a start of 10, end of 20 and comparing the results. It won't be the next 10 albums in alphabetical order.

GetArtists does it correctly, but at the very high cost of querying the database for ALL artists, then sorting and applying the limit.

Neither way is right... in an ideal world the sorting/limiting should be done by the database, not the libjson code. But that would require changes to the database code, outside of libjsonrpc.

This also leads to an inconsistency in the "total" parameter returned by libjsonrpc: For GetAlbums with start 0 and end 10 it will return 10, for GetArtists it will return the number of Artists in the database. I opened a Trac ticket for the totals problem in September (http://trac.xbmc.org/ticket/10146)

Hmm well, 'ideal world' is not really appropriate i think, this is all sql-101. Select A, B from table C order by D limit x,y

Undecided


- ncarthy - 2011-01-13

Problem is that current coding guidelines do not allow ad hoc sql requests... you must go through the interface exposed by the musicdatabase object. I don't think there's a suitable method or if there is it's not being used.

My workaround was to load all the albums into memory and do my own sorting/limiting.


- litemotiv - 2011-01-13

ncarthy Wrote:My workaround was to load all the albums into memory and do my own sorting/limiting.

Yes, that's not really an option for me, since it takes ages to parse on a mobile phone...


- vinc - 2011-01-14

Is there any way to get library information from a tv-show episode or movie? Stuff like plot, release year, rating etc.? Can't find the right method to call and "VideoLibrary.GetMovieInfo" seems to be deprecated?


- Montellese - 2011-01-14

vinc Wrote:Is there any way to get library information from a tv-show episode or movie? Stuff like plot, release year, rating etc.? Can't find the right method to call and "VideoLibrary.GetMovieInfo" seems to be deprecated?

You need to use the "VideoLibrary.GetMovies" method and provide an array of all the fields you want. (AFAIK) Possible field values for movies are:
Code:
"title", "genre", "year", "rating", "director", "file", "trailer", "tagline", "plot", "plotoutline", "originaltitle", "lastplayed", "duration", "playcount", "writer", "studio", "mpaa", "movieid"



- vinc - 2011-01-14

Montellese Wrote:You need to use the "VideoLibrary.GetMovies" method and provide an array of all the fields you want. (AFAIK) Possible field values for movies are:
Code:
"title", "genre", "year", "rating", "director", "file", "trailer", "tagline", "plot", "plotoutline", "originaltitle", "lastplayed", "duration", "playcount", "writer", "studio", "mpaa", "movieid"

Ah great! Thanks! The wiki didn't make clear you can use GetMovies for this!


- vinc - 2011-01-15

Montellese Wrote:You need to use the "VideoLibrary.GetMovies" method and provide an array of all the fields you want. (AFAIK) Possible field values for movies are:
Code:
"title", "genre", "year", "rating", "director", "file", "trailer", "tagline", "plot", "plotoutline", "originaltitle", "lastplayed", "duration", "playcount", "writer", "studio", "mpaa", "movieid"

I think I didn't explain good enough what I wanted to do; I want to query the information for a SINGLE movie of tvshow, should I be using the above method? I can't seem to get it working.


- wuench - 2011-01-15

So I get that I can get the fanart, thumbnail, etc locations with VideoPlaylist.GetItems.

Is there a method to retrieve JPG's from the HTTP interface using the special:// URLs it returns?


- Montellese - 2011-01-15

vinc Wrote:I think I didn't explain good enough what I wanted to do; I want to query the information for a SINGLE movie of tvshow, should I be using the above method? I can't seem to get it working.
Ah sorry misunderstood you there. Dharma does not contain methods to get the details of a single movie/episode/song but such methods are already implemented in the current development source code.

wuench Wrote:So I get that I can get the fanart, thumbnail, etc locations with VideoPlaylist.GetItems.

Is there a method to retrieve JPG's from the HTTP interface using the special:// URLs it returns?
Do you want to know how you can download files from the paths provided by the json rpc responses? If so give "Files.Download" a try. It takes an xbmc-specific path and returns an URL from where you can download the specified file.


- wuench - 2011-01-15

Montellese Wrote:Ah sorry misunderstood you there. Dharma does not contain methods to get the details of a single movie/episode/song but such methods are already implemented in the current development source code.


Do you want to know how you can download files from the paths provided by the json rpc responses? If so give "Files.Download" a try. It takes an xbmc-specific path and returns an URL from where you can download the specified file.

I am writing a driver for CharmedQuark(CQC) and I don't have access to decode image data so Files.Download won't work for me. I was looking for a way to get the actual JPG served by the web interface and I think I found it by decoding the Javascript in the web interface. Glad that is using the JSON commands, it provides some pretty good examples if you can read JQuery. Smile

So to access a special:// URI you just use:
Code:
Usage:
http://<server>:<port>/vfs/<specialURI>

Example:
http://theaterpc:8888/vfs/special://masterprofile/Thumbnails/Video/1/1642ecd5.tbn



- Xedar - 2011-01-19

Hi!

is there a way to get the id tag in every { } ?
when i parse the JSON i must use an } as EOM otherwise iam not able to fetch everything.
eg.

Code:
{
   "id" : 50,
   "jsonrpc" : "2.0",
   "result" : {
      "end" : 2,
      "movies" : [
         {
            "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/a8c81876.tbn",
            "file" : "/home/xedar/movietest/Arn.vid.vägens.ände/arnvägen.mkv",
            "label" : "Arn - The Kingdom at Road's End",
            "movieid" : 1,
            "originaltitle" : "Arn - Riket vid vägens slut",
            "rating" : 9.0,
            "thumbnail" : "special://masterprofile/Thumbnails/Video/a/a8c81876.tbn"
         },
         {
            "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/7655f397.tbn",
            "file" : "/home/xedar/movietest/Sommar.med.göran/sommargöran.mkv",
            "label" : "Sommaren med Göran – En midsommarnattskomedi",
            "movieid" : 2,
            "originaltitle" : "Sommaren med Göran – En midsommarnattskomedi",
            "rating" : 4.50,
            "thumbnail" : "special://masterprofile/Thumbnails/Video/7/7655f397.tbn"
         }
      ],
      "start" : 0,
      "total" : 2
   }
}

it would be great to have the
Code:
"id" : 50,
as a field, then my parser knows where it belongs.
I match with regex eg.

Movies
Code:
"id" : 50,.*[\r\n\w]+"file" : "(.*)",.*[\r\n\w]+"label" : "(.*)",
Music
Code:
"id" : 40,.*[\r\n\w]+"file" : "(.*)",.*[\r\n\w]+"label" : "(.*)",
Sorry if this has bean discussed before, this thread is getting huge! Smile

Best regards Mikael


- Montellese - 2011-01-19

I'm not sure I understand what you want. The "id" tag should be used to match a response from XBMC to a request you sent yourself. Furthermore if you get a json object without an "id" tag it indicates that you received an announcement and not a response.

If you write your own parser you should basically count the number of { and } to determine the end of a message. And you should use a json library which can read a json object and detect the available fields and their values and not use regular expressions because there are alot of different response objects and I don't think you would want to write regex's for all of them.


- Xedar - 2011-01-19

Montellese Wrote:I'm not sure I understand what you want. The "id" tag should be used to match a response from XBMC to a request you sent yourself. Furthermore if you get a json object without an "id" tag it indicates that you received an announcement and not a response.

If you write your own parser you should basically count the number of { and } to determine the end of a message. And you should use a json library which can read a json object and detect the available fields and their values and not use regular expressions because there are alot of different response objects and I don't think you would want to write regex's for all of them.

Hi Montellese

I want the "id", alot of them! in every { } Smile
like this
Code:
{
   "id" : 50,
   "jsonrpc" : "2.0",
   "result" : {
      "end" : 2,
      "movies" : [
         {
           "id" : 50,
           "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/a8c81876.tbn",
            "file" : "/home/xedar/movietest/Arn.vid.vägens.ände/arnvägen.mkv",
            "label" : "Arn - The Kingdom at Road's End",
            "movieid" : 1,
            "originaltitle" : "Arn - Riket vid vägens slut",
            "rating" : 9.0,
            "thumbnail" : "special://masterprofile/Thumbnails/Video/a/a8c81876.tbn"
         },
         {
            "id" : 50,
            "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/7655f397.tbn",
            "file" : "/home/xedar/movietest/Sommar.med.göran/sommargöran.mkv",
            "label" : "Sommaren med Göran – En midsommarnattskomedi",
            "movieid" : 2,
            "originaltitle" : "Sommaren med Göran – En midsommarnattskomedi",
            "rating" : 4.50,
            "thumbnail" : "special://masterprofile/Thumbnails/Video/7/7655f397.tbn"
         }
      ],
      "start" : 0,
      "total" : 2
   }
}

Problem is iam limited to none JSON, i send request to raw TCP and match with regex.
We use Iviewer for Ipad http://www.commandfusion.com/

right now I do it ugly, matching the "movieid" field instead of id # for movies and yes regex can be a pain when parsing alot...
I can understand its not a good feature to change standard JSON outputs.

Best regards.


- topfs2 - 2011-01-19

Xedar Wrote:Hi Montellese

I want the "id", alot of them! in every { } Smile
like this
Code:
{
   "id" : 50,
   "jsonrpc" : "2.0",
   "result" : {
      "end" : 2,
      "movies" : [
         {
           "id" : 50,
           "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/a8c81876.tbn",
            "file" : "/home/xedar/movietest/Arn.vid.vägens.ände/arnvägen.mkv",
            "label" : "Arn - The Kingdom at Road's End",
            "movieid" : 1,
            "originaltitle" : "Arn - Riket vid vägens slut",
            "rating" : 9.0,
            "thumbnail" : "special://masterprofile/Thumbnails/Video/a/a8c81876.tbn"
         },
         {
            "id" : 50,
            "fanart" : "special://masterprofile/Thumbnails/Video/Fanart/7655f397.tbn",
            "file" : "/home/xedar/movietest/Sommar.med.göran/sommargöran.mkv",
            "label" : "Sommaren med Göran – En midsommarnattskomedi",
            "movieid" : 2,
            "originaltitle" : "Sommaren med Göran – En midsommarnattskomedi",
            "rating" : 4.50,
            "thumbnail" : "special://masterprofile/Thumbnails/Video/7/7655f397.tbn"
         }
      ],
      "start" : 0,
      "total" : 2
   }
}

Problem is iam limited to none JSON, i send request to raw TCP and match with regex.
We use Iviewer for Ipad http://www.commandfusion.com/

right now I do it ugly, matching the "movieid" field instead of id # for movies and yes regex can be a pain when parsing alot...
I can understand its not a good feature to change standard JSON outputs.

Best regards.

Not in jsonrpc 2.0 spec, not happening. You know you can save the ID variable somewhere in the memory when you parse down the tree...