Finished up #68 and #62

This commit is contained in:
tidusjar 2016-03-25 16:54:18 +00:00
parent b96087d089
commit 3d2c787062
11 changed files with 161 additions and 17 deletions

View file

@ -26,17 +26,18 @@
#endregion #endregion
using System; using System;
using System.Threading.Tasks;
using PlexRequests.Api.Models.SickRage; using PlexRequests.Api.Models.SickRage;
namespace PlexRequests.Api.Interfaces namespace PlexRequests.Api.Interfaces
{ {
public interface ISickRageApi public interface ISickRageApi
{ {
SickRageTvAdd AddSeries(int tvdbId, int seasoncount, int[] seasons, string quality, string apiKey, Task<SickRageTvAdd> AddSeries(int tvdbId, int seasoncount, int[] seasons, string quality, string apiKey,
Uri baseUrl); Uri baseUrl);
SickRagePing Ping(string apiKey, Uri baseUrl); SickRagePing Ping(string apiKey, Uri baseUrl);
SickRageTvAdd AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl); Task<SickRageTvAdd> AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl);
} }
} }

View file

@ -60,6 +60,7 @@
<Compile Include="Plex\PlexUserRequest.cs" /> <Compile Include="Plex\PlexUserRequest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SickRage\SickRagePing.cs" /> <Compile Include="SickRage\SickRagePing.cs" />
<Compile Include="SickRage\SickRageShowInformation.cs" />
<Compile Include="SickRage\SickRageStatus.cs" /> <Compile Include="SickRage\SickRageStatus.cs" />
<Compile Include="SickRage\SickRageTvAdd.cs" /> <Compile Include="SickRage\SickRageTvAdd.cs" />
<Compile Include="Sonarr\SonarrAddSeries.cs" /> <Compile Include="Sonarr\SonarrAddSeries.cs" />

View file

@ -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<object> archive { get; set; }
public List<string> 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<string> 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<object> rls_ignore_words { get; set; }
public List<object> 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; }
}
}

View file

@ -28,7 +28,10 @@
#endregion #endregion
using System; using System;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NLog; using NLog;
using PlexRequests.Api.Interfaces; using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.SickRage; using PlexRequests.Api.Models.SickRage;
@ -49,7 +52,7 @@ namespace PlexRequests.Api
private ApiRequest Api { get; } private ApiRequest Api { get; }
public SickRageTvAdd AddSeries(int tvdbId, int seasonCount, int[] seasons, string quality, string apiKey, public async Task<SickRageTvAdd> AddSeries(int tvdbId, int seasonCount, int[] seasons, string quality, string apiKey,
Uri baseUrl) Uri baseUrl)
{ {
var futureStatus = seasons.Length > 0 && !seasons.Any(x => x == seasonCount) ? SickRageStatus.Skipped : SickRageStatus.Wanted; 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<SickRageTvAdd>(request, baseUrl); var obj = Api.Execute<SickRageTvAdd>(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 //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("SickRage adding season results: ");
Log.Trace(result.DumpJson()); Log.Trace(result.DumpJson());
} }
@ -99,7 +123,7 @@ namespace PlexRequests.Api
return obj; return obj;
} }
public SickRageTvAdd AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl) public async Task<SickRageTvAdd> AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl)
{ {
var request = new RestRequest var request = new RestRequest
{ {
@ -111,7 +135,22 @@ namespace PlexRequests.Api
request.AddQueryParameter("season", season.ToString()); request.AddQueryParameter("season", season.ToString());
request.AddQueryParameter("status", SickRageStatus.Wanted); request.AddQueryParameter("status", SickRageStatus.Wanted);
var obj = Api.Execute<SickRageTvAdd>(request, baseUrl); await Task.Run(() => Thread.Sleep(2000));
return await Task.Run(() => Api.Execute<SickRageTvAdd>(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<SickRageShowInformation>(request, baseUrl);
return obj; return obj;
} }

View file

@ -214,6 +214,12 @@ $(document).on("click", ".approve", function (e) {
var buttonId = e.target.id; var buttonId = e.target.id;
var $form = $('#approve' + buttonId); var $form = $('#approve' + buttonId);
if ($('#' + buttonId).text === "Loading...") {
return;
}
loadingButton(buttonId, "success");
$.ajax({ $.ajax({
type: $form.prop('method'), type: $form.prop('method'),
url: $form.prop('action'), url: $form.prop('action'),

View file

@ -60,7 +60,7 @@ $(document).on("click", ".dropdownTv", function (e) {
$(document).on("click", ".requestMovie", function (e) { $(document).on("click", ".requestMovie", function (e) {
var buttonId = e.target.id; var buttonId = e.target.id;
$("#" + buttonId).prop("disabled", true); $("#" + buttonId).prop("disabled", true);
loadingButton(buttonId, "primary");
e.preventDefault(); e.preventDefault();
var $form = $('#form' + buttonId); var $form = $('#form' + buttonId);

View file

@ -23,3 +23,15 @@ function checkJsonResponse(response) {
return false; return false;
} }
} }
function loadingButton(elementId, originalCss) {
$('#' + elementId).removeClass("btn-" + originalCss + "-outline");
$('#' + elementId).addClass("btn-primary-outline");
$('#' + elementId).html("<i class='fa fa-spinner fa-spin'></i> Loading...");
}
function finishLoading(elementId, originalCss, html) {
$('#' + elementId).removeClass("btn-primary-outline");
$('#' + elementId).addClass("btn-" + originalCss + "-outline");
$('#' + elementId).html(html);
}

View file

@ -71,7 +71,7 @@ namespace PlexRequests.UI.Helpers
Log.Trace("SickRage Add Result: "); Log.Trace("SickRage Add Result: ");
Log.Trace(result.DumpJson()); Log.Trace(result.DumpJson());
return result; return result.Result;
} }
} }
} }

View file

@ -1,8 +1,8 @@
<form method="POST" id="mainForm"> <form method="POST" id="mainForm">
<br /> <br />
Old Password <input class="form-control" name="OldPassword" type="password" /> Old Password <input class="form-control form-control-custom" name="OldPassword" type="password" /><br />
New Password <input class="form-control" name="NewPassword" type="password" /> New Password <input class="form-control form-control-custom" name="NewPassword" type="password" /><br />
New Password again <input class="form-control" name="NewPasswordAgain" type="password" /> New Password again <input class="form-control form-control-custom" name="NewPasswordAgain" type="password" />
<br /> <br />
<br /> <br />
<input class="btn btn-success-outline" id="save" type="submit" value="Change Password" /> <input class="btn btn-success-outline" id="save" type="submit" value="Change Password" />

View file

@ -1,7 +1,7 @@
<form method="POST"> <form method="POST">
Username <input class="form-control" type="text" name="Username"/> Username <input class="form-control form-control-custom" type="text" name="Username"/>
<br/> <br/>
Password <input class="form-control" name="Password" type="password"/> Password <input class="form-control form-control-custom" name="Password" type="password"/>
<br/> <br/>
Remember Me <input name="RememberMe" type="checkbox" value="True"/> Remember Me <input name="RememberMe" type="checkbox" value="True"/>
<br/> <br/>

View file

@ -21,7 +21,7 @@
<!-- Movie tab --> <!-- Movie tab -->
<div role="tabpanel" class="tab-pane active" id="MoviesTab"> <div role="tabpanel" class="tab-pane active" id="MoviesTab">
<div class="input-group"> <div class="input-group">
<input id="movieSearchContent" type="text" class="form-control"> <input id="movieSearchContent" type="text" class="form-control form-control-custom">
<div class="input-group-addon"> <div class="input-group-addon">
<i id="movieSearchButton" class="fa fa-search"></i> <i id="movieSearchButton" class="fa fa-search"></i>
</div> </div>
@ -40,7 +40,7 @@
<!-- TV tab --> <!-- TV tab -->
<div role="tabpanel" class="tab-pane" id="TvShowTab"> <div role="tabpanel" class="tab-pane" id="TvShowTab">
<div class="input-group"> <div class="input-group">
<input id="tvSearchContent" type="text" class="form-control"> <input id="tvSearchContent" type="text" class="form-control form-control-custom">
<div class="input-group-addon"> <div class="input-group-addon">
<i id="tvSearchButton" class="fa fa-search"></i> <i id="tvSearchButton" class="fa fa-search"></i>
</div> </div>