-
Notifications
You must be signed in to change notification settings - Fork 5
Methods
In this example we will be adding the VideoLibrary.GetMovieDetails method.
To get started you will have to browse to the Kodi JSON-RPC API v6 docs. You should be able to get everything you need by going through these docs and running a bunch of curl requests.
Search for the method that you want to implement on the right hand side, under Contents and click on it. In our case it will be VideoLibrary.GetMovieDetails. You'll see that the method is in the VideoLibrary namespace, requires a movieId as a parameter and takes an optional properties parameter. It also shows you that it will return a Video.Details.Movie
object called moviedetails as part of the result.
Let's go ahead and set up our classes. Your first step is to create the VideoLibrary directory under KodiRPC.Responses
. Create a new class called GetMovieDetailsResponse under the KodiRPC.Responses.VideoLibrary
namespace and populate it with the following code:
using Newtonsoft.Json;
namespace KodiRPC.Responses.VideoLibrary
{
public class GetMovieDetailsResponse
{
[JsonProperty(PropertyName = "moviedetails")]
public Movie Result { get; set; }
}
}
The class and file name should be the method name that you want to add plus Response. The moviedetails property name comes from the Returns: section in the docs. This tells the JSON parser to map the moviedetails object to our Movie object. The Movie class will be our representation of the moviedetails object that Kodi returns.
Let's create the Movie class. Click on the Video.Details.Movie link under the Returns: section. Notice that the Movie class is under the Video.Details
namespace. In the solution it will be under KodiRPC.Responses.Types.Video.Details
. Create all the directories to make up that namespace. Create a new class under the new namespace called Movie and add the following code to it:
using Newtonsoft.Json;
namespace KodiRPC.Responses.Types.Video.Details
{
public class Movie
{
}
}
Notice that the Movie class in the docs extends the Video.Details.File
class. Add a new class under KodiRPC.Responses.Types.Video.Details
called File and change the Movie class to extend it: public class Movie : File
.
Now you just need to work through all the properties in the documentation, adding any new classes that you need as you go along. Once you're done, click on the Video.Details.File and continue mapping properties in our File class. Keep on clicking through until you reach the base class.
Your final KodiRPC.Responses.Types.Video.Movie
class should look like this:
using Newtonsoft.Json;
namespace KodiRPC.Responses.Types.Video.Details
{
public class Movie : File
{
[JsonProperty(PropertyName = "plotoutline")]
public string PlotOutline { get; set; } = "";
[JsonProperty(PropertyName = "sorttitle")]
public string SortTitle { get; set; } = "";
[JsonProperty(PropertyName = "movieid")]
public int MovieId { get; set; }
[JsonProperty(PropertyName = "cast")]
public Cast[] Cast { get; set; }
[JsonProperty(PropertyName = "votes")]
public string Votes { get; set; } = "";
[JsonProperty(PropertyName = "showlink")]
public string[] ShowLink { get; set; }
[JsonProperty(PropertyName = "top250")]
public int Top250 { get; set; } = 0;
[JsonProperty(PropertyName = "trailer")]
public string Trailer { get; set; } = "";
[JsonProperty(PropertyName = "year")]
public int Year { get; set; } = 0;
[JsonProperty(PropertyName = "country")]
public string[] Country { get; set; }
[JsonProperty(PropertyName = "studio")]
public string[] Studio { get; set; }
[JsonProperty(PropertyName = "set")]
public string Set { get; set; } = "";
[JsonProperty(PropertyName = "genre")]
public string[] Genre { get; set; }
[JsonProperty(PropertyName = "mpaa")]
public string MPAA { get; set; } = "";
[JsonProperty(PropertyName = "setid")]
public int SetId { get; set; } = -1;
[JsonProperty(PropertyName = "rating")]
public int Rating { get; set; } = 0;
[JsonProperty(PropertyName = "tag")]
public string[] Tag { get; set; }
[JsonProperty(PropertyName = "tagline")]
public string Tagline { get; set; } = "";
[JsonProperty(PropertyName = "writer")]
public string[] Writer { get; set; }
[JsonProperty(PropertyName = "originaltitle")]
public string OriginalTitle { get; set; } = "";
[JsonProperty(PropertyName = "imdbnumber")]
public string ImdbNumber { get; set; } = "";
}
}
The final step is add your method to the specification under KodiRPC.RPC.Specifications.KodieMethods
and to add it to the service under KodiRPC.Service.KodiService
. Make sure to add it under the appropriate region. Create one if you have to.
Specification
namespace KodiRPC.SRPC.Specifications
{
public class KodiMethods
{
#region VideoLibrary
public static string GetMovieDetails => "VideoLibrary.GetMovieDetails";
#endregion
}
}
Service
namespace KodiRPC.Service
{
public class KodiService
{
#region VideoLibrary
public GetMovieDetailsResponse GetMovieDetails(int movieId, string[] properties = null, string requestId="GetMovieDetailsResponse")
{
properties = properties ?? new string[0];
var parameters = new
{
movieid = movieId,
properties
};
return _rpcConnector.MakeRequest<GetMovieDetailsResponse>(KodiMethods.GetMovieDetails, parameters, requestId);
}
#endregion
}
}