Implimented the new TV show Provider (needed for Sonarr TheTvDB)

pull/13/head
tidusjar 9 years ago
parent a8b6137ef8
commit ff81e67ab0

@ -0,0 +1,33 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: Authentication.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
namespace RequestPlex.Api.Models.Tv
{
public class Authentication
{
public string token { get; set; }
}
}

@ -0,0 +1,68 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: TvSearchResult.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.Collections.Generic;
namespace RequestPlex.Api.Models.Tv
{
public class TvShow
{
public int id { get; set; }
public int airedSeason { get; set; }
public int airedEpisodeNumber { get; set; }
public string episodeName { get; set; }
public string firstAired { get; set; }
public string guestStars { get; set; }
public string director { get; set; }
public List<string> writers { get; set; }
public string overview { get; set; }
public string productionCode { get; set; }
public string showUrl { get; set; }
public int lastUpdated { get; set; }
public string dvdDiscid { get; set; }
public int dvdSeason { get; set; }
public int dvdEpisodeNumber { get; set; }
public int dvdChapter { get; set; }
public int absoluteNumber { get; set; }
public string filename { get; set; }
public string seriesId { get; set; }
public string lastUpdatedBy { get; set; }
public int airsAfterSeason { get; set; }
public int airsBeforeSeason { get; set; }
public int airsBeforeEpisode { get; set; }
public string thumbAuthor { get; set; }
public string thumbAdded { get; set; }
public string thumbWidth { get; set; }
public string thumbHeight { get; set; }
public string imdbId { get; set; }
public int siteRating { get; set; }
}
public class TvSearchResult
{
public TvShow[] data { get; set; }
}
}

@ -24,14 +24,16 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using RequestPlex.Helpers;
namespace RequestPlex.Api
{
public abstract class MovieBase
public abstract class TvBase
{
private static readonly string Encrypted = "0T3QNSseexLO7n7UPiJvl70Y+KKnvbeTlsusl7Kwq0hPH0BHOuFNGwksNCjkwqWedyDdI/MJeUR4wtL4bIl0Z+//uHXEaYM/4H2pjeLbH5EWdUe5TTj1AhaIR5PQweamvcienRyFD/3YPCC/+qL5mHkKXBkPumMod3Zb/4yN0Ik=";
protected string ApiKey = StringCipher.Decrypt(Encrypted, "ApiKey");
protected string Url = "http://api.themoviedb.org/3";
protected Uri Url = new Uri("http://api.themoviedb.org/3");
}
}

@ -1,10 +1,34 @@
using System;
using System.IO;
using System.Runtime.Remoting.Messaging;
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexApi.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 RequestPlex.Api.Models;
using RestSharp;
using RestSharp.Deserializers;
using RestSharp.Serializers;
namespace RequestPlex.Api
{
@ -18,11 +42,11 @@ namespace RequestPlex.Api
{
password = password,
login = username
},
}
};
var request = new RestRequest
{
Method = Method.POST,
Method = Method.POST
};
request.AddHeader("X-Plex-Client-Identifier", "Test213"); // TODO need something unique to the users version/installation

@ -64,10 +64,14 @@
<Compile Include="Models\PlexAuthentication.cs" />
<Compile Include="Models\PlexFriends.cs" />
<Compile Include="Models\PlexUserRequest.cs" />
<Compile Include="Models\Tv\Authentication.cs" />
<Compile Include="Models\Tv\TvSearchResult.cs" />
<Compile Include="TvBase.cs" />
<Compile Include="PlexApi.cs" />
<Compile Include="TheMovieDbApi.cs" />
<Compile Include="MovieBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TheTvDbApi.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TMDbLib.Client;
@ -23,9 +24,9 @@ namespace RequestPlex.Api
return results.Results;
}
[Obsolete("Should use TheTvDbApi for TV")]
public async Task<List<SearchTv>> SearchTv(string searchTerm)
{
var results = await Client.SearchTvShow(searchTerm);
return results.Results;
}
@ -47,6 +48,7 @@ namespace RequestPlex.Api
return movies;
}
[Obsolete("Should use TheTvDbApi for TV")]
public async Task<TvShow> GetTvShowInformation(int tmdbId)
{
var show = await Client.GetTvShow(tmdbId);

@ -0,0 +1,118 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: TheTvDbApi.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 Newtonsoft.Json;
using RequestPlex.Api.Models.Tv;
using RestSharp;
namespace RequestPlex.Api
{
public class TheTvDbApi : TvBase
{
public TheTvDbApi()
{
Api = new ApiRequest();
}
private ApiRequest Api { get; }
/// <summary>
/// Authenticates against TheTVDB.
/// </summary>
/// <returns></returns>
public Authentication Authenticate()
{
var request = new RestRequest
{
Method = Method.POST,
Resource = "login"
};
var apiKey = new { apikey = ApiKey };
var json = JsonConvert.SerializeObject(apiKey);
request.AddBody(json);
return Api.Execute<Authentication>(request, Url);
}
/// <summary>
/// Refreshes the token.
/// </summary>
/// <param name="oldToken">The old token.</param>
/// <returns></returns>
public Authentication RefreshToken(string oldToken)
{
var request = new RestRequest
{
Method = Method.POST,
Resource = "refresh_token"
};
request.AddHeader("Authorization", $"Bearer {oldToken}");
return Api.Execute<Authentication>(request, Url);
}
/// <summary>
/// Searches for a tv series.
/// </summary>
/// <param name="searchTerm">The search term.</param>
/// <param name="token">The token.</param>
/// <returns></returns>
public TvSearchResult SearchTv(string searchTerm, string token)
{
var request = new RestRequest
{
Method = Method.POST,
Resource = "search/series?name={searchTerm}"
};
request.AddUrlSegment("searchTerm", searchTerm);
request.AddHeader("Authorization", $"Bearer {token}");
return Api.Execute<TvSearchResult>(request, Url);
}
/// <summary>
/// Gets the information for a TV Series.
/// </summary>
/// <param name="tvdbId">The TVDB identifier.</param>
/// <param name="token">The token.</param>
/// <returns></returns>
public TvSearchResult GetInformation(int tvdbId, string token)
{
var request = new RestRequest
{
Method = Method.POST,
Resource = "search/{id}"
};
request.AddUrlSegment("id", tvdbId.ToString());
request.AddHeader("Authorization", $"Bearer {token}");
return Api.Execute<TvSearchResult>(request, Url);
}
}
}

@ -0,0 +1,37 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: TvBase.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 RequestPlex.Helpers;
namespace RequestPlex.Api
{
public abstract class MovieBase
{
private static readonly string Encrypted = "AVdhrVK6XX8anvrQgEyN/qNr9rk8ZPwy7/r1t5t5cKyUEzxcyk0L1v6dSxgE7hTCxvITUX2cWa6VlFMlTMgJWyuPZml7fN3csCHntgd/VGYro6VfNf24snZ/rQ3mf005";
protected string ApiKey = StringCipher.Decrypt(Encrypted, "ApiKey");
protected string Url = "https://api-beta.thetvdb.com/";
}
}
Loading…
Cancel
Save