diff --git a/RequestPlex.Api/Models/Tv/Authentication.cs b/RequestPlex.Api/Models/Tv/Authentication.cs new file mode 100644 index 000000000..93b4d6d8b --- /dev/null +++ b/RequestPlex.Api/Models/Tv/Authentication.cs @@ -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; } + } +} \ No newline at end of file diff --git a/RequestPlex.Api/Models/Tv/TvSearchResult.cs b/RequestPlex.Api/Models/Tv/TvSearchResult.cs new file mode 100644 index 000000000..8b9e4d246 --- /dev/null +++ b/RequestPlex.Api/Models/Tv/TvSearchResult.cs @@ -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 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; } + } +} diff --git a/RequestPlex.Api/MovieBase.cs b/RequestPlex.Api/MovieBase.cs index 6a4b719dd..fa10e88fb 100644 --- a/RequestPlex.Api/MovieBase.cs +++ b/RequestPlex.Api/MovieBase.cs @@ -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"); } } diff --git a/RequestPlex.Api/PlexApi.cs b/RequestPlex.Api/PlexApi.cs index 20f4b5421..6668b5185 100644 --- a/RequestPlex.Api/PlexApi.cs +++ b/RequestPlex.Api/PlexApi.cs @@ -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 diff --git a/RequestPlex.Api/RequestPlex.Api.csproj b/RequestPlex.Api/RequestPlex.Api.csproj index bc26a3015..be86dbb2f 100644 --- a/RequestPlex.Api/RequestPlex.Api.csproj +++ b/RequestPlex.Api/RequestPlex.Api.csproj @@ -64,10 +64,14 @@ + + + + diff --git a/RequestPlex.Api/TheMovieDbApi.cs b/RequestPlex.Api/TheMovieDbApi.cs index 6ee80ab27..2fe1c2f6c 100644 --- a/RequestPlex.Api/TheMovieDbApi.cs +++ b/RequestPlex.Api/TheMovieDbApi.cs @@ -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> 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 GetTvShowInformation(int tmdbId) { var show = await Client.GetTvShow(tmdbId); diff --git a/RequestPlex.Api/TheTvDbApi.cs b/RequestPlex.Api/TheTvDbApi.cs new file mode 100644 index 000000000..68ceb7f5b --- /dev/null +++ b/RequestPlex.Api/TheTvDbApi.cs @@ -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; } + + /// + /// Authenticates against TheTVDB. + /// + /// + 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(request, Url); + } + + /// + /// Refreshes the token. + /// + /// The old token. + /// + public Authentication RefreshToken(string oldToken) + { + var request = new RestRequest + { + Method = Method.POST, + Resource = "refresh_token" + }; + request.AddHeader("Authorization", $"Bearer {oldToken}"); + + return Api.Execute(request, Url); + } + + /// + /// Searches for a tv series. + /// + /// The search term. + /// The token. + /// + 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(request, Url); + } + + + /// + /// Gets the information for a TV Series. + /// + /// The TVDB identifier. + /// The token. + /// + 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(request, Url); + } + } +} diff --git a/RequestPlex.Api/TvBase.cs b/RequestPlex.Api/TvBase.cs new file mode 100644 index 000000000..2d1aa0a27 --- /dev/null +++ b/RequestPlex.Api/TvBase.cs @@ -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/"; + } +}