Firstpass integrating with CouchPotato

This commit is contained in:
tidusjar 2016-03-04 14:26:54 +00:00
commit 73635e06c3
7 changed files with 233 additions and 57 deletions

View file

@ -30,6 +30,9 @@ using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models;
@ -75,11 +78,29 @@ namespace PlexRequests.Api
throw new ApplicationException(message, response.ErrorException);
}
var result = Deserialize<T>(response.Content);
var result = DeserializeXml<T>(response.Content);
return result;
}
public T Deserialize<T>(string input)
public T ExecuteJson<T>(IRestRequest request, Uri baseUri) where T : new()
{
var client = new RestClient { BaseUrl = baseUri };
var response = client.Execute(request);
if (response.ErrorException != null)
{
var message = "Error retrieving response. Check inner details for more info.";
throw new ApplicationException(message, response.ErrorException);
}
var json = JsonConvert.DeserializeObject<T>(response.Content);
return json;
}
public T DeserializeXml<T>(string input)
where T : class
{
var ser = new XmlSerializer(typeof(T));

View file

@ -0,0 +1,62 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: CouchPotatoApi.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using Newtonsoft.Json.Linq;
using PlexRequests.Api.Models.Movie;
using RestSharp;
namespace PlexRequests.Api
{
public class CouchPotatoApi
{
public CouchPotatoApi()
{
Api = new ApiRequest();
}
private ApiRequest Api { get; set; }
public bool AddMovie(string imdbid, string apiKey, string title, string baseUrl)
{
var request = new RestRequest { Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}" };
request.AddUrlSegment("apikey", apiKey);
request.AddUrlSegment("imdbid", imdbid);
request.AddUrlSegment("title", title);
var obj = Api.ExecuteJson<JObject>(request, new Uri(baseUrl));
if (obj.Count > 0)
{
var result = (bool)obj["success"];
return result;
}
return false;
}
}
}

View file

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlexRequests.Api.Models.Movie
{
public class CouchPotatoAdd
{
public Movie movie { get; set; }
public bool success { get; set; }
}
public class Rating
{
public List<double> imdb { get; set; }
}
public class Images
{
public List<object> disc_art { get; set; }
public List<string> poster { get; set; }
public List<object> extra_thumbs { get; set; }
public List<string> poster_original { get; set; }
public List<object> landscape { get; set; }
public string[] actors { get; set; }
public List<string> backdrop_original { get; set; }
public List<object> clear_art { get; set; }
public List<object> logo { get; set; }
public List<object> banner { get; set; }
public List<string> backdrop { get; set; }
public List<object> extra_fanart { get; set; }
}
public class Info
{
public Rating rating { get; set; }
public List<string> genres { get; set; }
public int tmdb_id { get; set; }
public string plot { get; set; }
public string tagline { get; set; }
public string original_title { get; set; }
public string[] actor_roles { get; set; }
public bool via_imdb { get; set; }
public string mpaa { get; set; }
public bool via_tmdb { get; set; }
public List<string> directors { get; set; }
public List<string> titles { get; set; }
public string imdb { get; set; }
public int year { get; set; }
public Images images { get; set; }
public List<string> actors { get; set; }
public List<string> writers { get; set; }
public int runtime { get; set; }
public string type { get; set; }
public string released { get; set; }
}
public class Identifiers
{
public string imdb { get; set; }
}
public class Movie
{
public string status { get; set; }
public Info info { get; set; }
public string _t { get; set; }
public List<object> releases { get; set; }
public string title { get; set; }
public string _rev { get; set; }
public string profile_id { get; set; }
public string _id { get; set; }
public object category_id { get; set; }
public string type { get; set; }
public Identifiers identifiers { get; set; }
}
}

View file

@ -61,6 +61,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApiRequest.cs" />
<Compile Include="CouchPotatoApi.cs" />
<Compile Include="Models\Movie\CouchPotatoAdd.cs" />
<Compile Include="Models\PlexAuthentication.cs" />
<Compile Include="Models\PlexError.cs" />
<Compile Include="Models\PlexFriends.cs" />