diff --git a/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs b/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs index 0e018e6a8..5d17f771d 100644 --- a/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs +++ b/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs @@ -1,41 +1,43 @@ -#region Copyright -// /************************************************************************ -// Copyright (c) 2016 Jamie Rees -// File: ICouchPotatoApi.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 PlexRequests.Api.Models.Movie; - -namespace PlexRequests.Api.Interfaces -{ - public interface ICouchPotatoApi - { - bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl, string profileID = default(string)); - CouchPotatoStatus GetStatus(Uri url, string apiKey); - CouchPotatoProfiles GetProfiles(Uri url, string apiKey); - CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status); - } +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: ICouchPotatoApi.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 PlexRequests.Api.Models.Movie; + +namespace PlexRequests.Api.Interfaces +{ + public interface ICouchPotatoApi + { + bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl, string profileID = default(string)); + CouchPotatoStatus GetStatus(Uri url, string apiKey); + CouchPotatoProfiles GetProfiles(Uri url, string apiKey); + CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status); + + CoucPotatoApiKey GetApiKey(Uri baseUrl, string username, string password); + } } \ No newline at end of file diff --git a/PlexRequests.Api.Models/Movie/CoucPotatoApiKey.cs b/PlexRequests.Api.Models/Movie/CoucPotatoApiKey.cs new file mode 100644 index 000000000..369d438c3 --- /dev/null +++ b/PlexRequests.Api.Models/Movie/CoucPotatoApiKey.cs @@ -0,0 +1,38 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CoucPotatoApiKey.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; + +namespace PlexRequests.Api.Models.Movie +{ + public class CoucPotatoApiKey + { + [JsonProperty("success")] + public bool Result { get; set; } + [JsonProperty("api_key")] + public string ApiKey { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Api.Models/Movie/CouchPotatoAdd.cs b/PlexRequests.Api.Models/Movie/CouchPotatoAdd.cs index 21c222974..63b20df1e 100644 --- a/PlexRequests.Api.Models/Movie/CouchPotatoAdd.cs +++ b/PlexRequests.Api.Models/Movie/CouchPotatoAdd.cs @@ -1,71 +1,91 @@ -using System; +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CouchPotatoAdd.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; -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 imdb { get; set; } } - - public class Images { - public List disc_art { get; set; } - public List poster { get; set; } - public List backdrop { get; set; } - public List extra_thumbs { get; set; } - public List poster_original { get; set; } public List actors { get; set; } + public List backdrop { get; set; } public List backdrop_original { get; set; } - public List clear_art { get; set; } - public List logo { get; set; } public List banner { get; set; } - public List landscape { get; set; } + public List clear_art { get; set; } + public List disc_art { get; set; } public List extra_fanart { get; set; } + public List extra_thumbs { get; set; } + public List landscape { get; set; } + public List logo { get; set; } + public List poster { get; set; } + public List poster_original { get; set; } } public class Info { - public Rating rating { get; set; } - public List genres { get; set; } - public int tmdb_id { get; set; } - public string plot { get; set; } - public string tagline { get; set; } - public Release_Date release_date { get; set; } - public int year { get; set; } - public string original_title { get; set; } public List actor_roles { get; set; } - public bool via_imdb { get; set; } - public Images images { get; set; } + public List actors { get; set; } public List directors { get; set; } - public List titles { get; set; } + public List genres { get; set; } + public Images images { get; set; } public string imdb { get; set; } public string mpaa { get; set; } - public bool via_tmdb { get; set; } - public List actors { get; set; } - public List writers { get; set; } - public int runtime { get; set; } - public string type { get; set; } + public string original_title { get; set; } + public string plot { get; set; } + public Rating rating { get; set; } + public Release_Date release_date { get; set; } public string released { get; set; } + public int runtime { get; set; } + public string tagline { get; set; } + public List titles { get; set; } + public int tmdb_id { get; set; } + public string type { get; set; } + public bool via_imdb { get; set; } + public bool via_tmdb { get; set; } + public List writers { get; set; } + public int year { get; set; } } public class Release_Date { + public bool bluray { get; set; } public int dvd { get; set; } public int expires { get; set; } public int theater { get; set; } - public bool bluray { get; set; } } public class Files @@ -80,21 +100,19 @@ namespace PlexRequests.Api.Models.Movie public class Movie { - public string status { get; set; } - public Info info { get; set; } - public string _t { get; set; } - public List 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 List tags { get; set; } - public int last_edit { get; set; } + public string _rev { get; set; } + public string _t { get; set; } public object category_id { get; set; } - public string type { get; set; } public Files files { get; set; } public Identifiers identifiers { get; set; } + public Info info { get; set; } + public int last_edit { get; set; } + public string profile_id { get; set; } + public List releases { get; set; } + public string status { get; set; } + public List tags { get; set; } + public string title { get; set; } + public string type { get; set; } } - - -} +} \ No newline at end of file diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj index 86bcfd77f..683e75456 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -1,111 +1,112 @@ - - - - - Debug - AnyCPU - {CB37A5F8-6DFC-4554-99D3-A42B502E4591} - Library - Properties - PlexRequests.Api.Models - PlexRequests.Api.Models - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {1252336D-42A3-482A-804C-836E60173DFA} - PlexRequests.Helpers - - - - + + + + + Debug + AnyCPU + {CB37A5F8-6DFC-4554-99D3-A42B502E4591} + Library + Properties + PlexRequests.Api.Models + PlexRequests.Api.Models + v4.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {1252336D-42A3-482A-804C-836E60173DFA} + PlexRequests.Helpers + + + + \ No newline at end of file diff --git a/PlexRequests.Api/CouchPotatoApi.cs b/PlexRequests.Api/CouchPotatoApi.cs index 4fbf28963..99f2563cc 100644 --- a/PlexRequests.Api/CouchPotatoApi.cs +++ b/PlexRequests.Api/CouchPotatoApi.cs @@ -31,6 +31,7 @@ using Newtonsoft.Json.Linq; using NLog; using PlexRequests.Api.Interfaces; using PlexRequests.Api.Models.Movie; +using PlexRequests.Helpers; using PlexRequests.Helpers.Exceptions; using RestSharp; @@ -159,5 +160,22 @@ namespace PlexRequests.Api return new CouchPotatoMovies(); } } + + public CoucPotatoApiKey GetApiKey(Uri baseUrl, string username, string password) + { + var request = new RestRequest + { + Resource = "getkey/?p={username}&u={password}", + Method = Method.GET + }; + + request.AddUrlSegment("username", StringHasher.CalcuateMD5Hash(username)); + request.AddUrlSegment("password", StringHasher.CalcuateMD5Hash(password)); + + var obj = RetryHandler.Execute(() => Api.Execute(request, baseUrl), null, + (exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan)); + + return obj; + } } } \ No newline at end of file diff --git a/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs b/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs index 030ff16b8..f22cb0b66 100644 --- a/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs +++ b/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs @@ -1,59 +1,61 @@ -#region Copyright -// /************************************************************************ -// Copyright (c) 2016 Jamie Rees -// File: CouchPotatoSettings.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; -using PlexRequests.Helpers; - -namespace PlexRequests.Core.SettingModels -{ - public class CouchPotatoSettings : Settings - { - public bool Enabled { get; set; } - public string Ip { get; set; } - public int Port { get; set; } - public string ApiKey { get; set; } - public bool Ssl { get; set; } - public string ProfileId { get; set; } - public string SubDir { get; set; } - - [JsonIgnore] - public Uri FullUri - { - get - { - if (!string.IsNullOrEmpty(SubDir)) - { - var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); - return formattedSubDir; - } - var formatted = Ip.ReturnUri(Port, Ssl); - return formatted; - } - } - } +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CouchPotatoSettings.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; +using PlexRequests.Helpers; + +namespace PlexRequests.Core.SettingModels +{ + public class CouchPotatoSettings : Settings + { + public bool Enabled { get; set; } + public string Ip { get; set; } + public int Port { get; set; } + public string ApiKey { get; set; } + public bool Ssl { get; set; } + public string ProfileId { get; set; } + public string SubDir { get; set; } + public string Username { get; set; } + public string Password { get; set; } + + [JsonIgnore] + public Uri FullUri + { + get + { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } + var formatted = Ip.ReturnUri(Port, Ssl); + return formatted; + } + } + } } \ No newline at end of file diff --git a/PlexRequests.Helpers/PlexRequests.Helpers.csproj b/PlexRequests.Helpers/PlexRequests.Helpers.csproj index 5a19b7b1a..0bb72a5a8 100644 --- a/PlexRequests.Helpers/PlexRequests.Helpers.csproj +++ b/PlexRequests.Helpers/PlexRequests.Helpers.csproj @@ -80,6 +80,7 @@ + diff --git a/PlexRequests.Helpers/StringHasher.cs b/PlexRequests.Helpers/StringHasher.cs new file mode 100644 index 000000000..d91e42d5d --- /dev/null +++ b/PlexRequests.Helpers/StringHasher.cs @@ -0,0 +1,52 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: StringHasher.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.Security.Cryptography; +using System.Text; + +namespace PlexRequests.Helpers +{ + public class StringHasher + { + public static string CalcuateMD5Hash(string input) + { + using (var md5 = MD5.Create()) + { + var inputBytes = Encoding.ASCII.GetBytes(input); + var hash = md5.ComputeHash(inputBytes); + + var sb = new StringBuilder(); + + foreach (byte t in hash) + { + sb.Append(t.ToString("x2")); + } + + return sb.ToString(); + } + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index 12685eea7..f84f2e49c 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -171,6 +171,7 @@ namespace PlexRequests.UI.Modules Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles(); Post["/cpprofiles", true] = async (x,ct) => await GetCpProfiles(); + Post["/cpapikey", true] = async (x,ct) => await GetCpApiKey(); Get["/emailnotification"] = _ => EmailNotifications(); Post["/emailnotification"] = _ => SaveEmailNotifications(); @@ -696,6 +697,20 @@ namespace PlexRequests.UI.Modules return Response.AsJson(profiles); } + private async Task GetCpApiKey() + { + var settings = this.Bind(); + + if (string.IsNullOrEmpty(settings.Username) || string.IsNullOrEmpty(settings.Password)) + { + return Response.AsJson(new { Message = "Please enter a username and password to request the Api Key", Result = false }); + } + var key = CpApi.GetApiKey(settings.FullUri, settings.Username, settings.Password); + + + return Response.AsJson(key); + } + private Negotiator Logs() { return View["Logs"]; diff --git a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml index 413dc278f..03654bb56 100644 --- a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml +++ b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml @@ -1,232 +1,271 @@ -@using PlexRequests.UI.Helpers -@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase -@Html.Partial("_Sidebar") -@{ - int port; - if (Model.Port == 0) - { - port = 5050; - } - else - { - port = Model.Port; - } -} -
-
-
- CouchPotato Settings -
-
- - @if (Model.Enabled) - { - - } - else - { - - } - -
-
-
- -
- -
-
- -
- - -
- -
-
- - -
- -
- -
-
-
-
- - @if (Model.Ssl) - { - - } - else - { - - } - -
-
-
- -
- -
-
- - -
-
- -
-
-
- -
- -
-
-
- -
-
- -
-
- - - - -
-
- -
-
-
-
-
- - - - \ No newline at end of file