From c376ea4ea0f19d2d6bae7b0d4f759e238f1f1803 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 17 Mar 2016 21:23:49 +0000 Subject: [PATCH 01/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e73e40abc..6fb5f53ce 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ We are looking for any contributions to the project! Just pick up a task, if you Please feed free to submit a pull request! # Donation -If you feel like donating you can [here!](paypal.me/PlexRequestsNet) +If you feel like donating you can [here!](https://paypal.me/PlexRequestsNet) # Sponsors From eeafd01106214bdd456a8936bb59ebb50bf9d494 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 17 Mar 2016 21:29:20 +0000 Subject: [PATCH 02/23] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 6fb5f53ce..5f4966d65 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,10 @@ Please feed free to submit a pull request! # Donation If you feel like donating you can [here!](https://paypal.me/PlexRequestsNet) +###### A massive thanks to everyone below! + +[heartisall](https://github.com/heartisall) + # Sponsors - [JetBrains](http://www.jetbrains.com/) for providing us with free licenses to their great tools!!! From 0edcecf71fc7240f5ab577670b3618f36f084cf8 Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 17 Mar 2016 22:01:11 +0000 Subject: [PATCH 03/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f4966d65..8b78102a0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ I wanted to write a similar application in .Net! #Preview -![Preview](http://i.imgur.com/yNztwTn.gif) +![Preview](http://i.imgur.com/ucCFUvd.gif) #Installation Download the latest [Release](https://github.com/tidusjar/PlexRequests.Net/releases). From 2786d13a17a3e376d97a1f8215782ec4f14980b1 Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Fri, 18 Mar 2016 21:50:00 +0000 Subject: [PATCH 04/23] Exploratory test for #37 --- PlexRequests.UI/Program.cs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/PlexRequests.UI/Program.cs b/PlexRequests.UI/Program.cs index 8a7d5a6ce..e1c145459 100644 --- a/PlexRequests.UI/Program.cs +++ b/PlexRequests.UI/Program.cs @@ -48,7 +48,7 @@ namespace PlexRequests.UI private static Logger Log = LogManager.GetCurrentClassLogger(); static void Main(string[] args) { - var uri = string.Empty; + var port = -1; if (args.Length > 0) { Log.Info("We are going to use port {0} that was passed in", args[0]); @@ -59,7 +59,7 @@ namespace PlexRequests.UI Console.ReadLine(); Environment.Exit(1); } - uri = $"http://*:{portResult}"; + port = portResult; } Log.Trace("Getting product version"); @@ -68,19 +68,21 @@ namespace PlexRequests.UI var s = new Setup(); s.SetupDb(); - if (string.IsNullOrEmpty(uri)) - uri = GetStartupUri(); + if (port == -1) + port = GetStartupPort(); - var options = new StartOptions(uri) + var options = new StartOptions { ServerFactory = "Microsoft.Owin.Host.HttpListener" }; + options.Urls.Add($"http://localhost:{port}"); + //options.Urls.Add($"http://127.0.0.1:{port}"); try { using (WebApp.Start(options)) { - Console.WriteLine($"Request Plex is running on {uri}"); + Console.WriteLine($"Request Plex is running on the following port: {port}"); Console.WriteLine("Press any key to exit"); Console.ReadLine(); } @@ -100,19 +102,19 @@ namespace PlexRequests.UI Console.WriteLine($"Version: {assemblyVer}"); } - private static string GetStartupUri() + private static int GetStartupPort() { - Log.Trace("Getting startup URI"); - var uri = "http://*:3579/"; + Log.Trace("Getting startup Port"); + var port = 3579; var service = new SettingsServiceV2(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider())); var settings = service.GetSettings(); Log.Trace("Port: {0}", settings.Port); if (settings.Port != 0) { - uri = $"http://*:{settings.Port}"; + port = settings.Port; } - return uri; + return port; } private static void ConfigureTargets(string connectionString) From 3c6338cadc2126f20ad8a00c69b849950186bc24 Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Fri, 18 Mar 2016 21:59:34 +0000 Subject: [PATCH 05/23] Catch the missing table exception when they have a new DB --- PlexRequests.Core/Setup.cs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index 4681dd3b4..ddb7a5a03 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -24,6 +24,8 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion + +using System; using System.Collections.Generic; using System.Linq; @@ -70,18 +72,29 @@ namespace PlexRequests.Core private void MigrateDb() // TODO: Remove when no longer needed { + var result = new List(); + RequestedModel[] requestedModels; var repo = new GenericRepository(Db); - var records = repo.GetAll(); - var requestedModels = records as RequestedModel[] ?? records.ToArray(); - if(!requestedModels.Any()) - { return; } + try + { + var records = repo.GetAll(); - var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider())); - var result = new List(); - foreach (var r in requestedModels) + requestedModels = records as RequestedModel[] ?? records.ToArray(); + if (!requestedModels.Any()) + { return; } + + var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider())); + + foreach (var r in requestedModels) + { + var id = jsonRepo.AddRequest(r); + result.Add(id); + } + } + catch (SqliteException) { - var id = jsonRepo.AddRequest(r); - result.Add(id); + // There is no requested table so they do not have an old version of the DB + return; } if (result.Any(x => x == -1)) From 1d814cd76e2f90efed1d2861e255e67b6fe96988 Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Fri, 18 Mar 2016 22:11:11 +0000 Subject: [PATCH 06/23] This should fix #37 --- PlexRequests.UI/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PlexRequests.UI/Program.cs b/PlexRequests.UI/Program.cs index e1c145459..08a353fca 100644 --- a/PlexRequests.UI/Program.cs +++ b/PlexRequests.UI/Program.cs @@ -75,8 +75,7 @@ namespace PlexRequests.UI { ServerFactory = "Microsoft.Owin.Host.HttpListener" }; - options.Urls.Add($"http://localhost:{port}"); - //options.Urls.Add($"http://127.0.0.1:{port}"); + options.Urls.Add($"http://+:{port}"); try { From cd682cdff9316d453f31e52fff39a983bb207ae9 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 18 Mar 2016 23:00:44 +0000 Subject: [PATCH 07/23] another test for #37 --- PlexRequests.Core/Setup.cs | 22 +++++++++++----------- PlexRequests.UI/Program.cs | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index ddb7a5a03..4486df9fb 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -78,24 +78,24 @@ namespace PlexRequests.Core try { var records = repo.GetAll(); - requestedModels = records as RequestedModel[] ?? records.ToArray(); - if (!requestedModels.Any()) - { return; } - - var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider())); - - foreach (var r in requestedModels) - { - var id = jsonRepo.AddRequest(r); - result.Add(id); - } } catch (SqliteException) { // There is no requested table so they do not have an old version of the DB return; } + if (!requestedModels.Any()) + { return; } + + var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider())); + + foreach (var r in requestedModels) + { + var id = jsonRepo.AddRequest(r); + result.Add(id); + } + if (result.Any(x => x == -1)) { diff --git a/PlexRequests.UI/Program.cs b/PlexRequests.UI/Program.cs index 08a353fca..134c6510c 100644 --- a/PlexRequests.UI/Program.cs +++ b/PlexRequests.UI/Program.cs @@ -75,7 +75,7 @@ namespace PlexRequests.UI { ServerFactory = "Microsoft.Owin.Host.HttpListener" }; - options.Urls.Add($"http://+:{port}"); + options.Urls.Add($"http://localhost:{port}/"); try { From a2d2121afe6f4cb8a7af1761f1c485081f1f39ff Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 18 Mar 2016 23:28:24 +0000 Subject: [PATCH 08/23] back to what it was :( --- PlexRequests.UI/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PlexRequests.UI/Program.cs b/PlexRequests.UI/Program.cs index 134c6510c..a16a5c393 100644 --- a/PlexRequests.UI/Program.cs +++ b/PlexRequests.UI/Program.cs @@ -71,11 +71,10 @@ namespace PlexRequests.UI if (port == -1) port = GetStartupPort(); - var options = new StartOptions + var options = new StartOptions($"http://+:{port}") { ServerFactory = "Microsoft.Owin.Host.HttpListener" }; - options.Urls.Add($"http://localhost:{port}/"); try { From 4136116555bef6ba4332d220c10a802ad4f5279a Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 18 Mar 2016 23:45:31 +0000 Subject: [PATCH 09/23] Added the code to lookup the old requests and refresh them with new information from TVMaze --- PlexRequests.Api/TvMazeApi.cs | 13 ++++++++++ PlexRequests.Core/PlexRequests.Core.csproj | 4 +++ PlexRequests.Core/Setup.cs | 29 ++++++++++++++++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/PlexRequests.Api/TvMazeApi.cs b/PlexRequests.Api/TvMazeApi.cs index 5f74ea7f2..8b6cb9f37 100644 --- a/PlexRequests.Api/TvMazeApi.cs +++ b/PlexRequests.Api/TvMazeApi.cs @@ -69,5 +69,18 @@ namespace PlexRequests.Api return Api.Execute(request, new Uri(Uri)); } + public TvMazeShow ShowLookupByTheTvDbId(int theTvDbId) + { + var request = new RestRequest + { + Method = Method.GET, + Resource = "lookup/shows?thetvdb={id}" + }; + request.AddUrlSegment("id", theTvDbId.ToString()); + request.AddHeader("Content-Type", "application/json"); + + return Api.Execute(request, new Uri(Uri)); + } + } } \ No newline at end of file diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index b7534d1b0..e1c4ee1f3 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -94,6 +94,10 @@ + + {CB37A5F8-6DFC-4554-99D3-A42B502E4591} + PlexRequests.Api.Models + {8CB8D235-2674-442D-9C6A-35FCAEEB160D} PlexRequests.Api diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index 4486df9fb..7cab60066 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Linq; using Mono.Data.Sqlite; +using PlexRequests.Api; using PlexRequests.Core.SettingModels; using PlexRequests.Helpers; using PlexRequests.Store; @@ -85,14 +86,38 @@ namespace PlexRequests.Core // There is no requested table so they do not have an old version of the DB return; } + if (!requestedModels.Any()) { return; } var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider())); - foreach (var r in requestedModels) + var api = new TvMazeApi(); + + foreach (var r in requestedModels.Where(x => x.Type == RequestType.TvShow)) { - var id = jsonRepo.AddRequest(r); + var show = api.ShowLookupByTheTvDbId(r.ProviderId); + + var model = new RequestedModel + { + Title = show.name, + PosterPath = show.image?.medium, + Type = RequestType.TvShow, + ProviderId = show.externals.thetvdb ?? 0, + ReleaseDate = r.ReleaseDate, + AdminNote = r.AdminNote, + Approved = r.Approved, + Available = r.Available, + ImdbId = show.externals.imdb, + Issues = r.Issues, + LatestTv = r.LatestTv, + OtherMessage = r.OtherMessage, + Overview = show.summary.RemoveHtml(), + RequestedBy = r.RequestedBy, + RequestedDate = r.ReleaseDate, + Status = show.status + }; + var id = jsonRepo.AddRequest(model); result.Add(id); } From e34170f55aa35da6471b27c6d24c8a0fac75a496 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 19 Mar 2016 00:16:44 +0000 Subject: [PATCH 10/23] Added the option to set a CP quality #38 --- .../ICouchPotatoApi.cs | 3 +- .../Movie/CouchPotatoProfiles.cs | 53 ++++++++++++++ .../PlexRequests.Api.Models.csproj | 1 + PlexRequests.Api/CouchPotatoApi.cs | 26 ++++++- .../SettingModels/CouchPotatoSettings.cs | 1 + PlexRequests.UI/Modules/AdminModule.cs | 14 +++- PlexRequests.UI/Modules/ApprovalModule.cs | 4 +- PlexRequests.UI/Modules/SearchModule.cs | 2 +- .../Views/Admin/CouchPotato.cshtml | 71 ++++++++++++++++++- 9 files changed, 166 insertions(+), 9 deletions(-) create mode 100644 PlexRequests.Api.Models/Movie/CouchPotatoProfiles.cs diff --git a/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs b/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs index bcfdb3dfd..288f09d67 100644 --- a/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs +++ b/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs @@ -33,7 +33,8 @@ namespace PlexRequests.Api.Interfaces { public interface ICouchPotatoApi { - bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl); + 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); } } \ No newline at end of file diff --git a/PlexRequests.Api.Models/Movie/CouchPotatoProfiles.cs b/PlexRequests.Api.Models/Movie/CouchPotatoProfiles.cs new file mode 100644 index 000000000..f63661ecb --- /dev/null +++ b/PlexRequests.Api.Models/Movie/CouchPotatoProfiles.cs @@ -0,0 +1,53 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CouchPotatoProfiles.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 PlexRequests.Api.Models.Movie +{ + public class ProfileList + { + public bool core { get; set; } + public string _rev { get; set; } + public List finish { get; set; } + public List qualities { get; set; } + public string _id { get; set; } + public string _t { get; set; } + public string label { get; set; } + public int minimum_score { get; set; } + public List stop_after { get; set; } + public List wait_for { get; set; } + public int order { get; set; } + public List __invalid_name__3d { get; set; } + } + + public class CouchPotatoProfiles + { + public List list { get; set; } + public bool success { 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 402cdd22a..1bdc4ffe9 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -46,6 +46,7 @@ + diff --git a/PlexRequests.Api/CouchPotatoApi.cs b/PlexRequests.Api/CouchPotatoApi.cs index bdb238ee2..7e660a38d 100644 --- a/PlexRequests.Api/CouchPotatoApi.cs +++ b/PlexRequests.Api/CouchPotatoApi.cs @@ -45,9 +45,17 @@ namespace PlexRequests.Api private ApiRequest Api { get; set; } private static Logger Log = LogManager.GetCurrentClassLogger(); - public bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl) + public bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl, string profileId = default(string)) { - var request = new RestRequest { Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}" }; + RestRequest request; + request = string.IsNullOrEmpty(profileId) + ? new RestRequest {Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}"} + : new RestRequest { Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}&profile_id={profileId}" }; + + if (!string.IsNullOrEmpty(profileId)) + { + request.AddUrlSegment("profileId", profileId); + } request.AddUrlSegment("apikey", apiKey); request.AddUrlSegment("imdbid", imdbid); @@ -93,5 +101,19 @@ namespace PlexRequests.Api return Api.Execute(request,url); } + + public CouchPotatoProfiles GetProfiles(Uri url, string apiKey) + { + Log.Trace("Getting CP Profiles, ApiKey = {0}", apiKey); + var request = new RestRequest + { + Resource = "api/{apikey}/profile.list/", + Method = Method.GET + }; + + request.AddUrlSegment("apikey", apiKey); + + return Api.Execute(request, url); + } } } \ No newline at end of file diff --git a/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs b/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs index 0c4ccd06f..7c18ca5d7 100644 --- a/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs +++ b/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs @@ -37,6 +37,7 @@ namespace PlexRequests.Core.SettingModels public int Port { get; set; } public string ApiKey { get; set; } public bool Ssl { get; set; } + public string ProfileId { get; set; } [JsonIgnore] public Uri FullUri diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index a41e6c967..fc86ad568 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -59,6 +59,7 @@ namespace PlexRequests.UI.Modules private IPlexApi PlexApi { get; } private ISonarrApi SonarrApi { get; } private PushbulletApi PushbulletApi { get; } + private ICouchPotatoApi CpApi { get; } private static Logger Log = LogManager.GetCurrentClassLogger(); public AdminModule(ISettingsService rpService, @@ -70,7 +71,8 @@ namespace PlexRequests.UI.Modules ISettingsService email, IPlexApi plexApi, ISettingsService pbSettings, - PushbulletApi pbApi) : base("admin") + PushbulletApi pbApi, + ICouchPotatoApi cpApi) : base("admin") { RpService = rpService; CpService = cpService; @@ -82,6 +84,7 @@ namespace PlexRequests.UI.Modules PlexApi = plexApi; PushbulletService = pbSettings; PushbulletApi = pbApi; + CpApi = cpApi; #if !DEBUG this.RequiresAuthentication(); @@ -107,6 +110,7 @@ namespace PlexRequests.UI.Modules Post["/sonarr"] = _ => SaveSonarr(); Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles(); + Post["/cpprofiles"] = _ => GetCpProfiles(); Get["/emailnotification"] = _ => EmailNotifications(); Post["/emailnotification"] = _ => SaveEmailNotifications(); @@ -354,5 +358,13 @@ namespace PlexRequests.UI.Modules ? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Pushbullet Notifications!" } : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); } + + private Response GetCpProfiles() + { + var settings = this.Bind(); + var profiles = CpApi.GetProfiles(settings.FullUri, settings.ApiKey); + + return Response.AsJson(profiles); + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/ApprovalModule.cs b/PlexRequests.UI/Modules/ApprovalModule.cs index ca3a4bcdb..74a26a6a2 100644 --- a/PlexRequests.UI/Modules/ApprovalModule.cs +++ b/PlexRequests.UI/Modules/ApprovalModule.cs @@ -127,7 +127,7 @@ namespace PlexRequests.UI.Modules var cpSettings = CpService.GetSettings(); var cp = new CouchPotatoApi(); Log.Info("Adding movie to CP : {0}", request.Title); - var result = cp.AddMovie(request.ImdbId, cpSettings.ApiKey, request.Title, cpSettings.FullUri); + var result = cp.AddMovie(request.ImdbId, cpSettings.ApiKey, request.Title, cpSettings.FullUri, cpSettings.ProfileId); Log.Trace("Adding movie to CP result {0}", result); if (result) { @@ -212,7 +212,7 @@ namespace PlexRequests.UI.Modules private bool SendMovie(CouchPotatoSettings settings, RequestedModel r, ICouchPotatoApi cp) { Log.Info("Adding movie to CP : {0}", r.Title); - var result = cp.AddMovie(r.ImdbId, settings.ApiKey, r.Title, settings.FullUri); + var result = cp.AddMovie(r.ImdbId, settings.ApiKey, r.Title, settings.FullUri, settings.ProfileId); Log.Trace("Adding movie to CP result {0}", result); return result; } diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 353a99c73..f56ac9b40 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -215,7 +215,7 @@ namespace PlexRequests.UI.Modules if (!settings.RequireApproval) { Log.Info("Adding movie to CP (No approval required)"); - var result = CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri); + var result = CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri,cpSettings.ProfileId); Log.Debug("Adding movie to CP result {0}", result); if (result) { diff --git a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml index 0b967436b..4be47db0a 100644 --- a/PlexRequests.UI/Views/Admin/CouchPotato.cshtml +++ b/PlexRequests.UI/Views/Admin/CouchPotato.cshtml @@ -52,6 +52,20 @@ + +
+
+ +
+
+
+ +
+ +
+
+
+
@@ -75,9 +89,58 @@ \ No newline at end of file From 1ebf80d1d120c2149dacdeadc87dfaa6219a4c30 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 19 Mar 2016 00:17:53 +0000 Subject: [PATCH 11/23] Fixed the new dependancy with the admin class tests --- PlexRequests.UI.Tests/AdminModuleTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PlexRequests.UI.Tests/AdminModuleTests.cs b/PlexRequests.UI.Tests/AdminModuleTests.cs index e10594a71..8e5ebbdc4 100644 --- a/PlexRequests.UI.Tests/AdminModuleTests.cs +++ b/PlexRequests.UI.Tests/AdminModuleTests.cs @@ -57,6 +57,7 @@ namespace PlexRequests.UI.Tests private Mock PlexMock { get; set; } private Mock SonarrApiMock { get; set; } private Mock PushbulletApi { get; set; } + private Mock CpApi { get; set; } private ConfigurableBootstrapper Bootstrapper { get; set; } @@ -79,6 +80,7 @@ namespace PlexRequests.UI.Tests EmailMock = new Mock>(); PushbulletApi = new Mock(); PushbulletSettings = new Mock>(); + CpApi = new Mock(); Bootstrapper = new ConfigurableBootstrapper(with => { @@ -93,6 +95,7 @@ namespace PlexRequests.UI.Tests with.Dependency(EmailMock.Object); with.Dependency(PushbulletApi.Object); with.Dependency(PushbulletSettings.Object); + with.Dependency(CpApi.Object); with.RootPathProvider(); with.RequestStartup((container, pipelines, context) => { From 803b12da0f609426fc5a71e9e7fa6a9de7d77806 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 19 Mar 2016 12:25:44 +0000 Subject: [PATCH 12/23] Added the api and settings page for Sickrage. Just need to do the tester and hook it up #40 --- PlexRequests.Api/PlexRequests.Api.csproj | 1 + PlexRequests.Api/SickrageApi.cs | 68 ++++++ .../SettingModels/SickRageSettings.cs | 19 +- .../SettingModels/SonarrSettings.cs | 1 + PlexRequests.UI.Tests/AdminModuleTests.cs | 3 + PlexRequests.UI/Bootstrapper.cs | 1 + PlexRequests.UI/Modules/AdminModule.cs | 41 +++- PlexRequests.UI/PlexRequests.UI.csproj | 4 + .../Validators/SickRageValidator.cs | 43 ++++ PlexRequests.UI/Views/Admin/Sickrage.cshtml | 197 ++++++++++++++++++ PlexRequests.UI/Views/Admin/Sonarr.cshtml | 17 +- PlexRequests.UI/Views/Admin/_Sidebar.cshtml | 9 +- 12 files changed, 399 insertions(+), 5 deletions(-) create mode 100644 PlexRequests.Api/SickrageApi.cs create mode 100644 PlexRequests.UI/Validators/SickRageValidator.cs create mode 100644 PlexRequests.UI/Views/Admin/Sickrage.cshtml diff --git a/PlexRequests.Api/PlexRequests.Api.csproj b/PlexRequests.Api/PlexRequests.Api.csproj index 5157e905c..2f204c975 100644 --- a/PlexRequests.Api/PlexRequests.Api.csproj +++ b/PlexRequests.Api/PlexRequests.Api.csproj @@ -73,6 +73,7 @@ + diff --git a/PlexRequests.Api/SickrageApi.cs b/PlexRequests.Api/SickrageApi.cs new file mode 100644 index 000000000..26dbdb3d7 --- /dev/null +++ b/PlexRequests.Api/SickrageApi.cs @@ -0,0 +1,68 @@ +#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 System.Collections.Generic; + +using NLog; +using PlexRequests.Api.Interfaces; +using PlexRequests.Api.Models.Sonarr; +using RestSharp; + +namespace PlexRequests.Api +{ + public class SickrageApi + { + public SickrageApi() + { + Api = new ApiRequest(); + } + private ApiRequest Api { get; set; } + private static Logger Log = LogManager.GetCurrentClassLogger(); + + + public SonarrAddSeries AddSeries(int tvdbId, string status, string futureStatus, string quality, string apiKey, Uri baseUrl) + { + //localhost:8081/api/e738882774aeb0b2210f4bc578cbb584/?cmd=show.addnew&tvdbid=101501&status=skipped&future_status=wanted&initial=fullhdbluray&sdtv + + var request = new RestRequest + { + Resource = "/api/{apiKey}/?cmd=show.addnew", + Method = Method.GET + }; + + request.AddQueryParameter("tvdbid", tvdbId.ToString()); + request.AddQueryParameter("status", status); + request.AddQueryParameter("future_status", futureStatus); + request.AddQueryParameter("initial", quality); + + var obj = Api.ExecuteJson(request, baseUrl); + + return obj; + } + + } +} \ No newline at end of file diff --git a/PlexRequests.Core/SettingModels/SickRageSettings.cs b/PlexRequests.Core/SettingModels/SickRageSettings.cs index b06801db4..344e41434 100644 --- a/PlexRequests.Core/SettingModels/SickRageSettings.cs +++ b/PlexRequests.Core/SettingModels/SickRageSettings.cs @@ -24,13 +24,30 @@ // 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 SickRageSettings : Settings { + public bool Enabled { get; set; } public string Ip { get; set; } public int Port { get; set; } public string ApiKey { get; set; } - public bool Enabled { get; set; } + public string QualityProfile { get; set; } + public bool Ssl { get; set; } + + [JsonIgnore] + public Uri FullUri + { + get + { + var formatted = Ip.ReturnUri(Port, Ssl); + return formatted; + } + } } } \ No newline at end of file diff --git a/PlexRequests.Core/SettingModels/SonarrSettings.cs b/PlexRequests.Core/SettingModels/SonarrSettings.cs index 15f486d37..2c128f993 100644 --- a/PlexRequests.Core/SettingModels/SonarrSettings.cs +++ b/PlexRequests.Core/SettingModels/SonarrSettings.cs @@ -33,6 +33,7 @@ namespace PlexRequests.Core.SettingModels { public class SonarrSettings : Settings { + public bool Enabled { get; set; } public string Ip { get; set; } public int Port { get; set; } public string ApiKey { get; set; } diff --git a/PlexRequests.UI.Tests/AdminModuleTests.cs b/PlexRequests.UI.Tests/AdminModuleTests.cs index 8e5ebbdc4..e42eb4a13 100644 --- a/PlexRequests.UI.Tests/AdminModuleTests.cs +++ b/PlexRequests.UI.Tests/AdminModuleTests.cs @@ -52,6 +52,7 @@ namespace PlexRequests.UI.Tests private Mock> AuthMock { get; set; } private Mock> PlexSettingsMock { get; set; } private Mock> SonarrSettingsMock { get; set; } + private Mock> SickRageSettingsMock { get; set; } private Mock> EmailMock { get; set; } private Mock> PushbulletSettings { get; set; } private Mock PlexMock { get; set; } @@ -81,6 +82,7 @@ namespace PlexRequests.UI.Tests PushbulletApi = new Mock(); PushbulletSettings = new Mock>(); CpApi = new Mock(); + SickRageSettingsMock = new Mock>(); Bootstrapper = new ConfigurableBootstrapper(with => { @@ -96,6 +98,7 @@ namespace PlexRequests.UI.Tests with.Dependency(PushbulletApi.Object); with.Dependency(PushbulletSettings.Object); with.Dependency(CpApi.Object); + with.Dependency(SickRageSettingsMock.Object); with.RootPathProvider(); with.RequestStartup((container, pipelines, context) => { diff --git a/PlexRequests.UI/Bootstrapper.cs b/PlexRequests.UI/Bootstrapper.cs index cba01fd25..358940c5c 100644 --- a/PlexRequests.UI/Bootstrapper.cs +++ b/PlexRequests.UI/Bootstrapper.cs @@ -73,6 +73,7 @@ namespace PlexRequests.UI container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); container.Register, GenericRepository>(); diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index fc86ad568..eeac628f0 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -54,6 +54,7 @@ namespace PlexRequests.UI.Modules private ISettingsService AuthService { get; } private ISettingsService PlexService { get; } private ISettingsService SonarrService { get; } + private ISettingsService SickRageService { get; } private ISettingsService EmailService { get; } private ISettingsService PushbulletService { get; } private IPlexApi PlexApi { get; } @@ -67,6 +68,7 @@ namespace PlexRequests.UI.Modules ISettingsService auth, ISettingsService plex, ISettingsService sonarr, + ISettingsService sickrage, ISonarrApi sonarrApi, ISettingsService email, IPlexApi plexApi, @@ -85,6 +87,7 @@ namespace PlexRequests.UI.Modules PushbulletService = pbSettings; PushbulletApi = pbApi; CpApi = cpApi; + SickRageService = sickrage; #if !DEBUG this.RequiresAuthentication(); @@ -109,6 +112,9 @@ namespace PlexRequests.UI.Modules Get["/sonarr"] = _ => Sonarr(); Post["/sonarr"] = _ => SaveSonarr(); + Get["/sickrage"] = _ => Sickrage(); + Post["/sickrage"] = _ => SaveSickrage(); + Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles(); Post["/cpprofiles"] = _ => GetCpProfiles(); @@ -283,7 +289,11 @@ namespace PlexRequests.UI.Modules { return Response.AsJson(valid.SendJsonError()); } - + var sickRageEnabled = SickRageService.GetSettings().Enabled; + if (sickRageEnabled) + { + return Response.AsJson(new JsonResponseModel { Result = false, Message = "SickRage is enabled, we cannot enable Sonarr and SickRage" }); + } var result = SonarrService.SaveSettings(sonarrSettings); return Response.AsJson(result @@ -291,6 +301,35 @@ namespace PlexRequests.UI.Modules : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); } + private Negotiator Sickrage() + { + var settings = SickRageService.GetSettings(); + + return View["Sickrage", settings]; + } + + private Response SaveSickrage() + { + var sickRageSettings = this.Bind(); + + var valid = this.Validate(sickRageSettings); + if (!valid.IsValid) + { + return Response.AsJson(valid.SendJsonError()); + } + + var sonarrEnabled = SonarrService.GetSettings().Enabled; + if (sonarrEnabled) + { + return Response.AsJson(new JsonResponseModel { Result = false, Message = "Sonarr is enabled, we cannot enable Sonarr and SickRage" }); + } + var result = SickRageService.SaveSettings(sickRageSettings); + + return Response.AsJson(result + ? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for SickRage!" } + : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); + } + private Response GetSonarrQualityProfiles() { var settings = this.Bind(); diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index ec0bf2acc..a5eed1bcf 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -165,6 +165,7 @@ + PreserveNewest @@ -320,6 +321,9 @@ Always + + Always + web.config diff --git a/PlexRequests.UI/Validators/SickRageValidator.cs b/PlexRequests.UI/Validators/SickRageValidator.cs new file mode 100644 index 000000000..28056e095 --- /dev/null +++ b/PlexRequests.UI/Validators/SickRageValidator.cs @@ -0,0 +1,43 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SonarrValidator.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 FluentValidation; + +using PlexRequests.Core.SettingModels; + +namespace PlexRequests.UI.Validators +{ + public class SickRageValidator : AbstractValidator + { + public SickRageValidator() + { + RuleFor(request => request.ApiKey).NotEmpty().WithMessage("You must specify a Api Key."); + RuleFor(request => request.Ip).NotEmpty().WithMessage("You must specify a IP/Host name."); + RuleFor(request => request.Port).NotEmpty().WithMessage("You must specify a Port."); + RuleFor(request => request.QualityProfile).NotEmpty().WithMessage("You must specify a Quality Profile."); + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Views/Admin/Sickrage.cshtml b/PlexRequests.UI/Views/Admin/Sickrage.cshtml new file mode 100644 index 000000000..34b17bb49 --- /dev/null +++ b/PlexRequests.UI/Views/Admin/Sickrage.cshtml @@ -0,0 +1,197 @@ +@Html.Partial("_Sidebar") +@{ + int port; + if (Model.Port == 0) + { + port = 8081; + } + else + { + port = Model.Port; + } +} +
+
+
+ SickRage Settings +
+
+ +
+
+
+ +
+ +
+
+ +
+ + +
+ +
+
+ + +
+ +
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+
+ +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/PlexRequests.UI/Views/Admin/Sonarr.cshtml b/PlexRequests.UI/Views/Admin/Sonarr.cshtml index 83a06c443..192161a23 100644 --- a/PlexRequests.UI/Views/Admin/Sonarr.cshtml +++ b/PlexRequests.UI/Views/Admin/Sonarr.cshtml @@ -14,7 +14,20 @@
Sonarr Settings - +
+
+ +
+
@@ -121,7 +134,7 @@ success: function(response) { response.forEach(function(result) { if (result.id == qualitySelected) { - + $("#select").append(""); } else { $("#select").append(""); diff --git a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml index 0626b06fd..2877729c7 100644 --- a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml +++ b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml @@ -44,7 +44,14 @@ { Sonarr } - @*Sickbeard Settings*@ + @if (Context.Request.Path == "/admin/sickrage") + { + SickRage + } + else + { + SickRage + } @if (Context.Request.Path == "/admin/emailnotification") { From 9402d1409e4cf834edffb5535e7f71df921623f2 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 19 Mar 2016 14:17:54 +0000 Subject: [PATCH 13/23] Wow, that was a lot of work. - So, I have now finished #40. - Fixed a bug where we was not choosing the correct tv series (Because of TVMaze) - Fixed a bug when checking for plex titles - Fixed a bug where the wrong issue would clean on the UI (DB was correct) - Refactored how we send tv shows - And too many small changes to count. --- PlexRequests.Api.Interfaces/ISickRageApi.cs | 40 +++++++ .../PlexRequests.Api.Interfaces.csproj | 1 + .../PlexRequests.Api.Models.csproj | 3 + .../SickRage/SickRagePing.cs | 40 +++++++ .../SickRage/SickRageStatus.cs | 35 ++++++ .../SickRage/SickRageTvAdd.cs | 41 +++++++ PlexRequests.Api/SickrageApi.cs | 42 +++++-- PlexRequests.Helpers/HtmlRemover.cs | 4 + .../PlexAvailabilityCheckerTests.cs | 2 +- .../PlexAvailabilityChecker.cs | 18 ++- .../Repository/RequestJsonRepository.cs | 2 +- PlexRequests.UI/Bootstrapper.cs | 16 +-- PlexRequests.UI/Content/requests.js | 2 +- PlexRequests.UI/Helpers/TvSender.cs | 77 +++++++++++++ .../Modules/ApplicationTesterModule.cs | 34 +++++- PlexRequests.UI/Modules/ApprovalModule.cs | 105 +++++++++++++++--- PlexRequests.UI/Modules/SearchModule.cs | 91 ++++++++++----- PlexRequests.UI/PlexRequests.UI.csproj | 1 + PlexRequests.UI/Views/Admin/Sickrage.cshtml | 67 ++++------- PlexRequests.UI/Views/Admin/Sonarr.cshtml | 5 - PlexRequests.UI/Views/Requests/Index.cshtml | 2 +- 21 files changed, 508 insertions(+), 120 deletions(-) create mode 100644 PlexRequests.Api.Interfaces/ISickRageApi.cs create mode 100644 PlexRequests.Api.Models/SickRage/SickRagePing.cs create mode 100644 PlexRequests.Api.Models/SickRage/SickRageStatus.cs create mode 100644 PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs create mode 100644 PlexRequests.UI/Helpers/TvSender.cs diff --git a/PlexRequests.Api.Interfaces/ISickRageApi.cs b/PlexRequests.Api.Interfaces/ISickRageApi.cs new file mode 100644 index 000000000..516b8784f --- /dev/null +++ b/PlexRequests.Api.Interfaces/ISickRageApi.cs @@ -0,0 +1,40 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: ISickRageApi.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.SickRage; + +namespace PlexRequests.Api.Interfaces +{ + public interface ISickRageApi + { + SickRageTvAdd AddSeries(int tvdbId, bool latest, string quality, string apiKey, + Uri baseUrl); + + SickRagePing Ping(string apiKey, Uri baseUrl); + } +} \ No newline at end of file diff --git a/PlexRequests.Api.Interfaces/PlexRequests.Api.Interfaces.csproj b/PlexRequests.Api.Interfaces/PlexRequests.Api.Interfaces.csproj index b76996490..3ea7be621 100644 --- a/PlexRequests.Api.Interfaces/PlexRequests.Api.Interfaces.csproj +++ b/PlexRequests.Api.Interfaces/PlexRequests.Api.Interfaces.csproj @@ -49,6 +49,7 @@ + diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj index 1bdc4ffe9..87a9951a6 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -57,6 +57,9 @@ + + + diff --git a/PlexRequests.Api.Models/SickRage/SickRagePing.cs b/PlexRequests.Api.Models/SickRage/SickRagePing.cs new file mode 100644 index 000000000..e3a7528da --- /dev/null +++ b/PlexRequests.Api.Models/SickRage/SickRagePing.cs @@ -0,0 +1,40 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SickRagePing.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 PlexRequests.Api.Models.SickRage +{ + public class SickRagePingData + { + public int pid { get; set; } + } + + public class SickRagePing + { + public SickRagePingData data { get; set; } + public string message { get; set; } + public string result { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Api.Models/SickRage/SickRageStatus.cs b/PlexRequests.Api.Models/SickRage/SickRageStatus.cs new file mode 100644 index 000000000..2ea03632d --- /dev/null +++ b/PlexRequests.Api.Models/SickRage/SickRageStatus.cs @@ -0,0 +1,35 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SickRageStatus.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 PlexRequests.Api.Models.SickRage +{ + public static class SickRageStatus + { + public const string Wanted = "wanted"; + public const string Skipped = "skipped"; + public const string Ignored = "Ignored"; + } +} \ No newline at end of file diff --git a/PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs b/PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs new file mode 100644 index 000000000..0fb021163 --- /dev/null +++ b/PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs @@ -0,0 +1,41 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SickRageTvAdd.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 PlexRequests.Api.Models.SickRage +{ + public class SickRageTvAddData + { + public string name { get; set; } + } + + public class SickRageTvAdd + { + public SickRageTvAddData data { get; set; } + public string message { get; set; } + public string result { get; set; } + } + +} \ No newline at end of file diff --git a/PlexRequests.Api/SickrageApi.cs b/PlexRequests.Api/SickrageApi.cs index 26dbdb3d7..a28ac21bf 100644 --- a/PlexRequests.Api/SickrageApi.cs +++ b/PlexRequests.Api/SickrageApi.cs @@ -1,4 +1,5 @@ #region Copyright + // /************************************************************************ // Copyright (c) 2016 Jamie Rees // File: CouchPotatoApi.cs @@ -23,46 +24,65 @@ // 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 System.Collections.Generic; +using System; using NLog; using PlexRequests.Api.Interfaces; -using PlexRequests.Api.Models.Sonarr; +using PlexRequests.Api.Models.SickRage; using RestSharp; namespace PlexRequests.Api { - public class SickrageApi + public class SickrageApi : ISickRageApi { + private static Logger Log = LogManager.GetCurrentClassLogger(); + public SickrageApi() { Api = new ApiRequest(); } - private ApiRequest Api { get; set; } - private static Logger Log = LogManager.GetCurrentClassLogger(); + + private ApiRequest Api { get; } - public SonarrAddSeries AddSeries(int tvdbId, string status, string futureStatus, string quality, string apiKey, Uri baseUrl) + public SickRageTvAdd AddSeries(int tvdbId, bool latest, string quality, string apiKey, + Uri baseUrl) { - //localhost:8081/api/e738882774aeb0b2210f4bc578cbb584/?cmd=show.addnew&tvdbid=101501&status=skipped&future_status=wanted&initial=fullhdbluray&sdtv + string status; + var futureStatus = SickRageStatus.Wanted; + + status = latest ? SickRageStatus.Skipped : SickRageStatus.Wanted; var request = new RestRequest { Resource = "/api/{apiKey}/?cmd=show.addnew", Method = Method.GET }; - + request.AddUrlSegment("apiKey", apiKey); request.AddQueryParameter("tvdbid", tvdbId.ToString()); request.AddQueryParameter("status", status); request.AddQueryParameter("future_status", futureStatus); request.AddQueryParameter("initial", quality); - - var obj = Api.ExecuteJson(request, baseUrl); + + var obj = Api.Execute(request, baseUrl); return obj; } + public SickRagePing Ping(string apiKey, Uri baseUrl) + { + var request = new RestRequest + { + Resource = "/api/{apiKey}/?cmd=sb.ping", + Method = Method.GET + }; + + request.AddUrlSegment("apiKey", apiKey); + var obj = Api.ExecuteJson(request, baseUrl); + + return obj; + } } } \ No newline at end of file diff --git a/PlexRequests.Helpers/HtmlRemover.cs b/PlexRequests.Helpers/HtmlRemover.cs index 64d23a6de..43d484255 100644 --- a/PlexRequests.Helpers/HtmlRemover.cs +++ b/PlexRequests.Helpers/HtmlRemover.cs @@ -33,6 +33,10 @@ namespace PlexRequests.Helpers { public static string RemoveHtml(this string value) { + if (string.IsNullOrEmpty(value)) + { + return string.Empty; + } var step1 = Regex.Replace(value, @"<[^>]+>| ", "").Trim(); var step2 = Regex.Replace(step1, @"\s{2,}", " "); return step2; diff --git a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs index 117157927..8e641181e 100644 --- a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs +++ b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs @@ -108,7 +108,7 @@ namespace PlexRequests.Services.Tests var requestMock = new Mock(); var plexMock = new Mock(); - var searchResult = new PlexSearch { Video = new List
@@ -100,10 +100,17 @@ + From af6deec3f09fcf5217d047876c111fa7247063f8 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 21 Mar 2016 19:05:01 +0000 Subject: [PATCH 23/23] Got the filter working on both movie and tv #57 --- PlexRequests.UI/Content/custom.css | 3 +++ PlexRequests.UI/Content/custom.min.css | 2 +- PlexRequests.UI/Content/custom.scss | 3 +++ PlexRequests.UI/Content/requests.js | 25 +++++++++++++-------- PlexRequests.UI/Views/Requests/Index.cshtml | 11 ++++----- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/PlexRequests.UI/Content/custom.css b/PlexRequests.UI/Content/custom.css index c571269b4..a517cc508 100644 --- a/PlexRequests.UI/Content/custom.css +++ b/PlexRequests.UI/Content/custom.css @@ -123,3 +123,6 @@ label { #movieList .mix { display: none; } +#tvList .mix { + display: none; } + diff --git a/PlexRequests.UI/Content/custom.min.css b/PlexRequests.UI/Content/custom.min.css index 8385aac7b..45dc19440 100644 --- a/PlexRequests.UI/Content/custom.min.css +++ b/PlexRequests.UI/Content/custom.min.css @@ -1 +1 @@ -@media(min-width:768px){.row{position:relative;}.bottom-align-text{position:absolute;bottom:0;right:0;}}@media(max-width:48em){.home{padding-top:1rem;}}@media(min-width:48em){.home{padding-top:4rem;}}.btn{border-radius:.25rem !important;}.multiSelect{background-color:#4e5d6c;}.form-control-custom{background-color:#4e5d6c !important;color:#fff !important;}h1{font-size:3.5rem !important;font-weight:600 !important;}.request-title{margin-top:0 !important;font-size:1.9rem !important;}p{font-size:1.1rem !important;}label{display:inline-block !important;margin-bottom:.5rem !important;font-size:16px !important;}.btn-danger-outline{color:#d9534f !important;background-color:transparent;background-image:none;border-color:#d9534f !important;}.btn-danger-outline:focus,.btn-danger-outline.focus,.btn-danger-outline:active,.btn-danger-outline.active,.btn-danger-outline:hover,.open>.btn-danger-outline.dropdown-toggle{color:#fff !important;background-color:#d9534f !important;border-color:#d9534f !important;}.btn-primary-outline{color:#ff761b !important;background-color:transparent;background-image:none;border-color:#ff761b !important;}.btn-primary-outline:focus,.btn-primary-outline.focus,.btn-primary-outline:active,.btn-primary-outline.active,.btn-primary-outline:hover,.open>.btn-primary-outline.dropdown-toggle{color:#fff !important;background-color:#df691a !important;border-color:#df691a !important;}.btn-info-outline{color:#5bc0de !important;background-color:transparent;background-image:none;border-color:#5bc0de !important;}.btn-info-outline:focus,.btn-info-outline.focus,.btn-info-outline:active,.btn-info-outline.active,.btn-info-outline:hover,.open>.btn-info-outline.dropdown-toggle{color:#fff !important;background-color:#5bc0de !important;border-color:#5bc0de !important;}.btn-warning-outline{color:#f0ad4e !important;background-color:transparent;background-image:none;border-color:#f0ad4e !important;}.btn-warning-outline:focus,.btn-warning-outline.focus,.btn-warning-outline:active,.btn-warning-outline.active,.btn-warning-outline:hover,.open>.btn-warning-outline.dropdown-toggle{color:#fff !important;background-color:#f0ad4e !important;border-color:#f0ad4e !important;}.btn-success-outline{color:#5cb85c !important;background-color:transparent;background-image:none;border-color:#5cb85c !important;}.btn-success-outline:focus,.btn-success-outline.focus,.btn-success-outline:active,.btn-success-outline.active,.btn-success-outline:hover,.open>.btn-success-outline.dropdown-toggle{color:#fff !important;background-color:#5cb85c !important;border-color:#5cb85c !important;}#movieList .mix{display:none;} \ No newline at end of file +@media(min-width:768px){.row{position:relative;}.bottom-align-text{position:absolute;bottom:0;right:0;}}@media(max-width:48em){.home{padding-top:1rem;}}@media(min-width:48em){.home{padding-top:4rem;}}.btn{border-radius:.25rem !important;}.multiSelect{background-color:#4e5d6c;}.form-control-custom{background-color:#4e5d6c !important;color:#fff !important;}h1{font-size:3.5rem !important;font-weight:600 !important;}.request-title{margin-top:0 !important;font-size:1.9rem !important;}p{font-size:1.1rem !important;}label{display:inline-block !important;margin-bottom:.5rem !important;font-size:16px !important;}.btn-danger-outline{color:#d9534f !important;background-color:transparent;background-image:none;border-color:#d9534f !important;}.btn-danger-outline:focus,.btn-danger-outline.focus,.btn-danger-outline:active,.btn-danger-outline.active,.btn-danger-outline:hover,.open>.btn-danger-outline.dropdown-toggle{color:#fff !important;background-color:#d9534f !important;border-color:#d9534f !important;}.btn-primary-outline{color:#ff761b !important;background-color:transparent;background-image:none;border-color:#ff761b !important;}.btn-primary-outline:focus,.btn-primary-outline.focus,.btn-primary-outline:active,.btn-primary-outline.active,.btn-primary-outline:hover,.open>.btn-primary-outline.dropdown-toggle{color:#fff !important;background-color:#df691a !important;border-color:#df691a !important;}.btn-info-outline{color:#5bc0de !important;background-color:transparent;background-image:none;border-color:#5bc0de !important;}.btn-info-outline:focus,.btn-info-outline.focus,.btn-info-outline:active,.btn-info-outline.active,.btn-info-outline:hover,.open>.btn-info-outline.dropdown-toggle{color:#fff !important;background-color:#5bc0de !important;border-color:#5bc0de !important;}.btn-warning-outline{color:#f0ad4e !important;background-color:transparent;background-image:none;border-color:#f0ad4e !important;}.btn-warning-outline:focus,.btn-warning-outline.focus,.btn-warning-outline:active,.btn-warning-outline.active,.btn-warning-outline:hover,.open>.btn-warning-outline.dropdown-toggle{color:#fff !important;background-color:#f0ad4e !important;border-color:#f0ad4e !important;}.btn-success-outline{color:#5cb85c !important;background-color:transparent;background-image:none;border-color:#5cb85c !important;}.btn-success-outline:focus,.btn-success-outline.focus,.btn-success-outline:active,.btn-success-outline.active,.btn-success-outline:hover,.open>.btn-success-outline.dropdown-toggle{color:#fff !important;background-color:#5cb85c !important;border-color:#5cb85c !important;}#movieList .mix{display:none;}#tvList .mix{display:none;} \ No newline at end of file diff --git a/PlexRequests.UI/Content/custom.scss b/PlexRequests.UI/Content/custom.scss index e1944c04c..11c81ec37 100644 --- a/PlexRequests.UI/Content/custom.scss +++ b/PlexRequests.UI/Content/custom.scss @@ -160,4 +160,7 @@ label { #movieList .mix{ display: none; +} +#tvList .mix{ + display: none; } \ No newline at end of file diff --git a/PlexRequests.UI/Content/requests.js b/PlexRequests.UI/Content/requests.js index 1d44e0625..68b942bdb 100644 --- a/PlexRequests.UI/Content/requests.js +++ b/PlexRequests.UI/Content/requests.js @@ -14,6 +14,22 @@ movieLoad(); tvLoad(); +$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { + var target = $(e.target).attr('href'); + if (target === "#TvShowTab") { + if (!$('#tvList').mixItUp('isLoaded')) { + $('#tvList').mixItUp({ + layout: { + display: 'block' + }, + load: { + filter: 'all' + } + }); + } + } +}); + // Approve all $('#approveAll').click(function () { $.ajax({ @@ -283,7 +299,6 @@ function movieLoad() { filter: 'all' } }); - }); }; @@ -296,14 +311,6 @@ function tvLoad() { var html = searchTemplate(context); $("#tvList").append(html); }); - $('#tvList').mixItUp({ - layout: { - display: 'block' - }, - load: { - filter: 'all' - } - }); }); }; diff --git a/PlexRequests.UI/Views/Requests/Index.cshtml b/PlexRequests.UI/Views/Requests/Index.cshtml index 1465935f5..5c1f38431 100644 --- a/PlexRequests.UI/Views/Requests/Index.cshtml +++ b/PlexRequests.UI/Views/Requests/Index.cshtml @@ -22,7 +22,7 @@ -