This project is read-only.

Project Description
The goal of this project is to provide a .Net client for the XBMC JSONRPC API. The main part is not XBMC dependent and may be used for any JSON-RPC client.

JSON-RPC Client Generator on my Website

General

The generator takes the JSON schema returned by the JSONRPC.Introspect method and generates C# types and methods. The classes should be compatible with .Net, Silverlight, WinRT and Windows Phone. These methods support the async/await feature of Visual Studio 2012.

The advantages of this auto generated .Net API client:

·         Containing ALL methods of the XBMC API

·         No manual maintenance of single methods

·         Uses the same type and method names used in the API documentation

·         Fast availability, if new methods are added to the XBMC API

This first release has been tested on .Net 4.5. I will test the generated code on Windows Phone 7 as soon as the new Windows Phone 8 SDK is released.

If you don’t want to wait and want to use the async/await feature for Windows Phone 7 development, you need the Async CTP for Visual Studio 2010. You should install this on a clean virtual machine because of the problems described in this post.

The generated code references the JSON.Net framework.

To generator code does not implement all aspects of JSON schema. Only the parts necessary to get the XBMC client running are implemented.

Source Code

The source code contains 3 projects:

·         JsonRpcGen – The generator for the client

·         XBMCRPC – A generated client from the current XBMC nightly builds

·         JsonTester – A sample  showing the usage of the client

XBMC dependent modifications

The ClientXBMC partial class contains some additions for easier usage of the JSON client. It is created from the file “JsonRpcGen\Templates\ClientXBMC.templ”.

The current nightly builds have a bug in the JSON schema. It reports the type “string” for the property “country” on type “List.Item.All”. But the API actually returns “string[]”. That’s why the most Windows Phone and Window 8 XBMC Apps are broken on Frodo.

I changed the type manually after generation in the checked in sample project XBMCRPC.

Sample Usage


var xbmc = new Client("localhost", 85, "xbmc", "xbmc");

var ret0 = await xbmc.JSONRPC.Introspect();
var ret1 = await xbmc.Application.GetProperties(Client.AllValues<Name>());
var ret2 = await xbmc.VideoLibrary.GetTVShows(TVShow.AllFields());

var ret3 = await xbmc.VideoLibrary.SetMovieDetails(97, playcount: 10);
var ret4 = await xbmc.VideoLibrary.GetMovies(Movie.AllFields(), new Limits() { start = 0, end = 20 });
var ret4a = await xbmc.Files.PrepareDownload(ret4.movies[0].thumbnail);
await xbmc.DownloadImage(ret4.movies[0].thumbnail, "tmb.jpg");

var ret5 = await xbmc.Files.GetSources();
var ret6 = await xbmc.Files.GetDirectory(@"C:\Users\steve_000\Music\Amazon MP3\die �rzte\auch", Media.music, Files.AllFields());
var ret7 = await xbmc.Playlist.GetItems(0, properties: All.AllFields());
var ret7a = await xbmc.Playlist.GetItems(1, properties: All.AllFields());
var ret8 = await xbmc.Playlist.GetPlaylists();
var ret9 = await xbmc.Player.GetActivePlayers();

Last edited Sep 30, 2012 at 1:44 PM by Pate, version 3