diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
index e24c0e31f..f04835277 100644
--- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
+++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
@@ -64,7 +64,9 @@
+
+
diff --git a/PlexRequests.Api.Models/SickRage/SickRageBase.cs b/PlexRequests.Api.Models/SickRage/SickRageBase.cs
new file mode 100644
index 000000000..f560c85e3
--- /dev/null
+++ b/PlexRequests.Api.Models/SickRage/SickRageBase.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PlexRequests.Api.Models.SickRage
+{
+ public class SickRageBase
+ {
+ public T data { get; set; }
+ public string message { get; set; }
+ public string result { get; set; }
+ }
+}
diff --git a/PlexRequests.Api.Models/SickRage/SickRagePing.cs b/PlexRequests.Api.Models/SickRage/SickRagePing.cs
index e3a7528da..46c8c94e7 100644
--- a/PlexRequests.Api.Models/SickRage/SickRagePing.cs
+++ b/PlexRequests.Api.Models/SickRage/SickRagePing.cs
@@ -31,10 +31,7 @@ namespace PlexRequests.Api.Models.SickRage
public int pid { get; set; }
}
- public class SickRagePing
+ public class SickRagePing : SickRageBase
{
- 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/SickRageSeasonList.cs b/PlexRequests.Api.Models/SickRage/SickRageSeasonList.cs
new file mode 100644
index 000000000..959e399d3
--- /dev/null
+++ b/PlexRequests.Api.Models/SickRage/SickRageSeasonList.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PlexRequests.Api.Models.SickRage
+{
+ public class SickRageSeasonList : SickRageBase
+ {
+ }
+}
diff --git a/PlexRequests.Api.Models/SickRage/SickRageShowInformation.cs b/PlexRequests.Api.Models/SickRage/SickRageShowInformation.cs
index 8076008a5..511f692ab 100644
--- a/PlexRequests.Api.Models/SickRage/SickRageShowInformation.cs
+++ b/PlexRequests.Api.Models/SickRage/SickRageShowInformation.cs
@@ -75,11 +75,8 @@ namespace PlexRequests.Api.Models.SickRage
public int tvdbid { get; set; }
}
- public class SickRageShowInformation
+ public class SickRageShowInformation : SickRageBase
{
- 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.Models/SickRage/SickRageTvAdd.cs b/PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs
index 0fb021163..15e2e3eae 100644
--- a/PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs
+++ b/PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs
@@ -31,11 +31,8 @@ namespace PlexRequests.Api.Models.SickRage
public string name { get; set; }
}
- public class SickRageTvAdd
+ public class SickRageTvAdd : SickRageBase
{
- 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 fc4714279..9d41b8419 100644
--- a/PlexRequests.Api/SickrageApi.cs
+++ b/PlexRequests.Api/SickrageApi.cs
@@ -74,17 +74,18 @@ namespace PlexRequests.Api
var obj = Api.Execute(request, baseUrl);
-
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))
+ var seasonIncrement = 0;
+ var seasonList = new SickRageSeasonList();
+ while (seasonIncrement < seasonCount)
{
- showInfo = CheckShowHasBeenAdded(tvdbId, apiKey, baseUrl);
+ seasonList = VerifyShowHasLoaded(tvdbId, apiKey, baseUrl);
+ seasonIncrement = seasonList.data?.Length ?? 0;
+
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.");
@@ -93,8 +94,6 @@ namespace PlexRequests.Api
}
sw.Stop();
}
-
-
if (seasons.Length > 0)
{
//handle the seasons requested
@@ -123,36 +122,35 @@ namespace PlexRequests.Api
return obj;
}
- public async Task AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl)
+ public SickRageSeasonList VerifyShowHasLoaded(int tvdbId, string apiKey, Uri baseUrl)
{
var request = new RestRequest
{
- Resource = "/api/{apiKey}/?cmd=episode.setstatus",
+ Resource = "/api/{apiKey}/?cmd=show.seasonlist",
Method = Method.GET
};
request.AddUrlSegment("apiKey", apiKey);
request.AddQueryParameter("tvdbid", tvdbId.ToString());
- request.AddQueryParameter("season", season.ToString());
- request.AddQueryParameter("status", SickRageStatus.Wanted);
- await Task.Run(() => Thread.Sleep(2000));
- return await Task.Run(() => Api.Execute(request, baseUrl)).ConfigureAwait(false);
- }
+ var obj = Api.ExecuteJson(request, baseUrl);
+ return obj;
+ }
- public SickRageShowInformation CheckShowHasBeenAdded(int tvdbId, string apiKey, Uri baseUrl)
+ public async Task AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl)
{
var request = new RestRequest
{
- Resource = "/api/{apiKey}/?cmd=show",
+ Resource = "/api/{apiKey}/?cmd=episode.setstatus",
Method = Method.GET
};
request.AddUrlSegment("apiKey", apiKey);
request.AddQueryParameter("tvdbid", tvdbId.ToString());
+ request.AddQueryParameter("season", season.ToString());
+ request.AddQueryParameter("status", SickRageStatus.Wanted);
- var obj = Api.Execute(request, baseUrl);
-
- return obj;
+ await Task.Run(() => Thread.Sleep(2000));
+ return await Task.Run(() => Api.Execute(request, baseUrl)).ConfigureAwait(false);
}
}
}
\ No newline at end of file