diff --git a/PlexRequests.Api.Interfaces/ISickRageApi.cs b/PlexRequests.Api.Interfaces/ISickRageApi.cs index a5770b56f..4953b16f6 100644 --- a/PlexRequests.Api.Interfaces/ISickRageApi.cs +++ b/PlexRequests.Api.Interfaces/ISickRageApi.cs @@ -26,17 +26,18 @@ #endregion using System; +using System.Threading.Tasks; using PlexRequests.Api.Models.SickRage; namespace PlexRequests.Api.Interfaces { public interface ISickRageApi { - SickRageTvAdd AddSeries(int tvdbId, int seasoncount, int[] seasons, string quality, string apiKey, + Task AddSeries(int tvdbId, int seasoncount, int[] seasons, string quality, string apiKey, Uri baseUrl); SickRagePing Ping(string apiKey, Uri baseUrl); - SickRageTvAdd AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl); + Task AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl); } } \ 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 fdbf08e5b..1ec1a67ae 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -60,6 +60,7 @@ + diff --git a/PlexRequests.Api.Models/SickRage/SickRageShowInformation.cs b/PlexRequests.Api.Models/SickRage/SickRageShowInformation.cs new file mode 100644 index 000000000..8076008a5 --- /dev/null +++ b/PlexRequests.Api.Models/SickRage/SickRageShowInformation.cs @@ -0,0 +1,85 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SickRageShowInformation.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.SickRage +{ + public class Cache + { + public int banner { get; set; } + public int poster { get; set; } + } + + public class QualityDetails + { + public List archive { get; set; } + public List initial { get; set; } + } + + public class SeasonList + { + } + + public class Data + { + public int air_by_date { get; set; } + public string airs { get; set; } + public int anime { get; set; } + public int archive_firstmatch { get; set; } + public Cache cache { get; set; } + public int dvdorder { get; set; } + public int flatten_folders { get; set; } + public List genre { get; set; } + public string imdbid { get; set; } + public int indexerid { get; set; } + public string language { get; set; } + public string location { get; set; } + public string network { get; set; } + public string next_ep_airdate { get; set; } + public int paused { get; set; } + public string quality { get; set; } + public QualityDetails quality_details { get; set; } + public List rls_ignore_words { get; set; } + public List rls_require_words { get; set; } + public int scene { get; set; } + public SeasonList season_list { get; set; } + public string show_name { get; set; } + public int sports { get; set; } + public string status { get; set; } + public int subtitles { get; set; } + public int tvdbid { get; set; } + } + + public class SickRageShowInformation + { + public Data 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 fe27968fe..fc4714279 100644 --- a/PlexRequests.Api/SickrageApi.cs +++ b/PlexRequests.Api/SickrageApi.cs @@ -28,7 +28,10 @@ #endregion using System; +using System.Diagnostics; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using NLog; using PlexRequests.Api.Interfaces; using PlexRequests.Api.Models.SickRage; @@ -49,7 +52,7 @@ namespace PlexRequests.Api private ApiRequest Api { get; } - public SickRageTvAdd AddSeries(int tvdbId, int seasonCount, int[] seasons, string quality, string apiKey, + public async Task AddSeries(int tvdbId, int seasonCount, int[] seasons, string quality, string apiKey, Uri baseUrl) { var futureStatus = seasons.Length > 0 && !seasons.Any(x => x == seasonCount) ? SickRageStatus.Skipped : SickRageStatus.Wanted; @@ -71,12 +74,33 @@ namespace PlexRequests.Api var obj = Api.Execute(request, baseUrl); - if (seasons.Length > 0 && obj.result != "failure") + + if (obj.result != "failure") + { + var sw = new Stopwatch(); + sw.Start(); + + // Check to see if it's been added yet. + var showInfo = new SickRageShowInformation { message = "Show not found" }; + while (showInfo.message.Equals("Show not found", StringComparison.CurrentCultureIgnoreCase)) + { + showInfo = CheckShowHasBeenAdded(tvdbId, apiKey, baseUrl); + if (sw.ElapsedMilliseconds > 30000) // Break out after 30 seconds, it's not going to get added + { + Log.Warn("Couldn't find out if the show had been added after 10 seconds. I doubt we can change the status to wanted."); + break; + } + } + sw.Stop(); + } + + + if (seasons.Length > 0) { //handle the seasons requested - foreach (int s in seasons) + foreach (var s in seasons) { - var result = AddSeason(tvdbId, s, apiKey, baseUrl); + var result = await AddSeason(tvdbId, s, apiKey, baseUrl); Log.Trace("SickRage adding season results: "); Log.Trace(result.DumpJson()); } @@ -99,7 +123,7 @@ namespace PlexRequests.Api return obj; } - public SickRageTvAdd AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl) + public async Task AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl) { var request = new RestRequest { @@ -111,7 +135,22 @@ namespace PlexRequests.Api request.AddQueryParameter("season", season.ToString()); request.AddQueryParameter("status", SickRageStatus.Wanted); - var obj = Api.Execute(request, baseUrl); + await Task.Run(() => Thread.Sleep(2000)); + return await Task.Run(() => Api.Execute(request, baseUrl)).ConfigureAwait(false); + } + + + public SickRageShowInformation CheckShowHasBeenAdded(int tvdbId, string apiKey, Uri baseUrl) + { + var request = new RestRequest + { + Resource = "/api/{apiKey}/?cmd=show", + Method = Method.GET + }; + request.AddUrlSegment("apiKey", apiKey); + request.AddQueryParameter("tvdbid", tvdbId.ToString()); + + var obj = Api.Execute(request, baseUrl); return obj; } diff --git a/PlexRequests.UI/Content/requests.js b/PlexRequests.UI/Content/requests.js index e05cd294d..13563f0bd 100644 --- a/PlexRequests.UI/Content/requests.js +++ b/PlexRequests.UI/Content/requests.js @@ -214,6 +214,12 @@ $(document).on("click", ".approve", function (e) { var buttonId = e.target.id; var $form = $('#approve' + buttonId); + if ($('#' + buttonId).text === "Loading...") { + return; + } + + loadingButton(buttonId, "success"); + $.ajax({ type: $form.prop('method'), url: $form.prop('action'), diff --git a/PlexRequests.UI/Content/search.js b/PlexRequests.UI/Content/search.js index 14168b5ce..176bb7d3c 100644 --- a/PlexRequests.UI/Content/search.js +++ b/PlexRequests.UI/Content/search.js @@ -60,7 +60,7 @@ $(document).on("click", ".dropdownTv", function (e) { $(document).on("click", ".requestMovie", function (e) { var buttonId = e.target.id; $("#" + buttonId).prop("disabled", true); - + loadingButton(buttonId, "primary"); e.preventDefault(); var $form = $('#form' + buttonId); diff --git a/PlexRequests.UI/Content/site.js b/PlexRequests.UI/Content/site.js index d16a70def..f05ca73d6 100644 --- a/PlexRequests.UI/Content/site.js +++ b/PlexRequests.UI/Content/site.js @@ -23,3 +23,15 @@ function checkJsonResponse(response) { return false; } } + +function loadingButton(elementId, originalCss) { + $('#' + elementId).removeClass("btn-" + originalCss + "-outline"); + $('#' + elementId).addClass("btn-primary-outline"); + $('#' + elementId).html(" Loading..."); +} + +function finishLoading(elementId, originalCss, html) { + $('#' + elementId).removeClass("btn-primary-outline"); + $('#' + elementId).addClass("btn-" + originalCss + "-outline"); + $('#' + elementId).html(html); +} \ No newline at end of file diff --git a/PlexRequests.UI/Helpers/TvSender.cs b/PlexRequests.UI/Helpers/TvSender.cs index 6c2f59ace..d26611321 100644 --- a/PlexRequests.UI/Helpers/TvSender.cs +++ b/PlexRequests.UI/Helpers/TvSender.cs @@ -71,7 +71,7 @@ namespace PlexRequests.UI.Helpers Log.Trace("SickRage Add Result: "); Log.Trace(result.DumpJson()); - return result; + return result.Result; } } } \ No newline at end of file diff --git a/PlexRequests.UI/Views/Login/ChangePassword.cshtml b/PlexRequests.UI/Views/Login/ChangePassword.cshtml index 73099f67b..17eb5f7da 100644 --- a/PlexRequests.UI/Views/Login/ChangePassword.cshtml +++ b/PlexRequests.UI/Views/Login/ChangePassword.cshtml @@ -1,8 +1,8 @@ 

- Old Password - New Password - New Password again + Old Password
+ New Password
+ New Password again

diff --git a/PlexRequests.UI/Views/Login/Index.cshtml b/PlexRequests.UI/Views/Login/Index.cshtml index 1d6a61793..6ca2e444c 100644 --- a/PlexRequests.UI/Views/Login/Index.cshtml +++ b/PlexRequests.UI/Views/Login/Index.cshtml @@ -1,7 +1,7 @@  - Username + Username
- Password + Password
Remember Me
diff --git a/PlexRequests.UI/Views/Search/Index.cshtml b/PlexRequests.UI/Views/Search/Index.cshtml index 553ac32d7..1e0a50cc2 100644 --- a/PlexRequests.UI/Views/Search/Index.cshtml +++ b/PlexRequests.UI/Views/Search/Index.cshtml @@ -21,7 +21,7 @@
- +
@@ -40,7 +40,7 @@
- +