Finished up #68 and #62

pull/88/head
tidusjar 8 years ago
parent b96087d089
commit 3d2c787062

@ -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<SickRageTvAdd> 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<SickRageTvAdd> AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl);
}
}

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

@ -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<SickRageTvAdd> 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<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
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<SickRageTvAdd> 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<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;
}

@ -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'),

@ -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);

@ -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("<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);
}

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

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

@ -1,7 +1,7 @@
<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/>
Password <input class="form-control" name="Password" type="password"/>
Password <input class="form-control form-control-custom" name="Password" type="password"/>
<br/>
Remember Me <input name="RememberMe" type="checkbox" value="True"/>
<br/>

@ -21,7 +21,7 @@
<!-- Movie tab -->
<div role="tabpanel" class="tab-pane active" id="MoviesTab">
<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">
<i id="movieSearchButton" class="fa fa-search"></i>
</div>
@ -40,7 +40,7 @@
<!-- TV tab -->
<div role="tabpanel" class="tab-pane" id="TvShowTab">
<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">
<i id="tvSearchButton" class="fa fa-search"></i>
</div>

Loading…
Cancel
Save