diff --git a/PlexRequests.Api.Interfaces/ISickRageApi.cs b/PlexRequests.Api.Interfaces/ISickRageApi.cs index 516b8784f..038caa26e 100644 --- a/PlexRequests.Api.Interfaces/ISickRageApi.cs +++ b/PlexRequests.Api.Interfaces/ISickRageApi.cs @@ -32,9 +32,11 @@ namespace PlexRequests.Api.Interfaces { public interface ISickRageApi { - SickRageTvAdd AddSeries(int tvdbId, bool latest, string quality, string apiKey, + SickRageTvAdd AddSeries(int tvdbId, bool latest, int[] seasons, string quality, string apiKey, Uri baseUrl); SickRagePing Ping(string apiKey, Uri baseUrl); + + SickRageTvAdd AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl); } } \ No newline at end of file diff --git a/PlexRequests.Api.Interfaces/ISonarrApi.cs b/PlexRequests.Api.Interfaces/ISonarrApi.cs index d9e7c61db..7939cd21d 100644 --- a/PlexRequests.Api.Interfaces/ISonarrApi.cs +++ b/PlexRequests.Api.Interfaces/ISonarrApi.cs @@ -36,7 +36,7 @@ namespace PlexRequests.Api.Interfaces List GetProfiles(string apiKey, Uri baseUrl); SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, - bool episodes, string apiKey, Uri baseUrl); + bool episodes, int[] seasons, string apiKey, Uri baseUrl); SystemStatus SystemStatus(string apiKey, Uri baseUrl); } diff --git a/PlexRequests.Api/Mocks/MockSonarrApi.cs b/PlexRequests.Api/Mocks/MockSonarrApi.cs index 8508d5a13..1694c3069 100644 --- a/PlexRequests.Api/Mocks/MockSonarrApi.cs +++ b/PlexRequests.Api/Mocks/MockSonarrApi.cs @@ -43,7 +43,7 @@ namespace PlexRequests.Api.Mocks return obj; } - public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, bool episodes, + public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, bool episodes, int[] seasons, string apiKey, Uri baseUrl) { var json = MockApiData.Sonarr_AddSeriesResult; diff --git a/PlexRequests.Api/SickrageApi.cs b/PlexRequests.Api/SickrageApi.cs index f81693f5d..c589f059c 100644 --- a/PlexRequests.Api/SickrageApi.cs +++ b/PlexRequests.Api/SickrageApi.cs @@ -31,6 +31,7 @@ using System; using NLog; using PlexRequests.Api.Interfaces; using PlexRequests.Api.Models.SickRage; +using PlexRequests.Helpers; using RestSharp; namespace PlexRequests.Api @@ -47,13 +48,13 @@ namespace PlexRequests.Api private ApiRequest Api { get; } - public SickRageTvAdd AddSeries(int tvdbId, bool latest, string quality, string apiKey, + public SickRageTvAdd AddSeries(int tvdbId, bool latest, int[] seasons, string quality, string apiKey, Uri baseUrl) { string status; var futureStatus = SickRageStatus.Wanted; - status = latest ? SickRageStatus.Skipped : SickRageStatus.Wanted; + status = latest || seasons.Length > 0 ? SickRageStatus.Skipped : SickRageStatus.Wanted; var request = new RestRequest { @@ -71,6 +72,17 @@ namespace PlexRequests.Api var obj = Api.Execute(request, baseUrl); + if (!latest && seasons.Length > 0 && obj.result != "failure") + { + //handle the seasons requested + foreach (int s in seasons) + { + var result = AddSeason(tvdbId, s, apiKey, baseUrl); + Log.Trace("SickRage adding season results: "); + Log.Trace(result.DumpJson()); + } + } + return obj; } @@ -87,5 +99,22 @@ namespace PlexRequests.Api return obj; } + + public SickRageTvAdd AddSeason(int tvdbId, int season, string apiKey, Uri baseUrl) + { + var request = new RestRequest + { + 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; + } } } \ No newline at end of file diff --git a/PlexRequests.Api/SonarrApi.cs b/PlexRequests.Api/SonarrApi.cs index 148f27d23..895c696ec 100644 --- a/PlexRequests.Api/SonarrApi.cs +++ b/PlexRequests.Api/SonarrApi.cs @@ -54,7 +54,7 @@ namespace PlexRequests.Api return obj; } - public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, bool episodes, string apiKey, Uri baseUrl) + public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, bool episodes, int[] seasons, string apiKey, Uri baseUrl) { var request = new RestRequest @@ -90,6 +90,19 @@ namespace PlexRequests.Api options.seasons = new List(); options.rootFolderPath = rootPath; + if (seasons.Length > 0) + { + foreach (int s in seasons) + { + var season = new Season + { + seasonNumber = s, + monitored = true + }; + options.seasons.Add(season); + } + } + request.AddHeader("X-Api-Key", apiKey); request.AddJsonBody(options); diff --git a/PlexRequests.Store/RequestedModel.cs b/PlexRequests.Store/RequestedModel.cs index 247433329..aaed042b1 100644 --- a/PlexRequests.Store/RequestedModel.cs +++ b/PlexRequests.Store/RequestedModel.cs @@ -25,6 +25,7 @@ namespace PlexRequests.Store public string OtherMessage { get; set; } public bool LatestTv { get; set; } public string AdminNote { get; set; } + public int[] SeasonList { get; set; } } public enum RequestType diff --git a/PlexRequests.UI/Content/search.js b/PlexRequests.UI/Content/search.js index 4e765594b..14168b5ce 100644 --- a/PlexRequests.UI/Content/search.js +++ b/PlexRequests.UI/Content/search.js @@ -39,9 +39,14 @@ $(document).on("click", ".dropdownTv", function (e) { var $form = $('#form' + buttonId); var data = $form.serialize(); var seasons = $(this).attr("season-select"); - if (seasons === "1") { + if (seasons === "2") { // Send over the latest - data = data + "&latest=true"; + data = data + "&seasons=latest"; + } + if (seasons === "1") { + // Send over the first season + data = data + "&seasons=first"; + } var type = $form.prop('method'); diff --git a/PlexRequests.UI/Helpers/TvSender.cs b/PlexRequests.UI/Helpers/TvSender.cs index 9e63749fc..f43012d36 100644 --- a/PlexRequests.UI/Helpers/TvSender.cs +++ b/PlexRequests.UI/Helpers/TvSender.cs @@ -54,7 +54,7 @@ namespace PlexRequests.UI.Helpers int qualityProfile; int.TryParse(sonarrSettings.QualityProfile, out qualityProfile); var result = SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile, - sonarrSettings.SeasonFolders, sonarrSettings.RootPath, model.LatestTv, sonarrSettings.ApiKey, + sonarrSettings.SeasonFolders, sonarrSettings.RootPath, model.LatestTv, model.SeasonList, sonarrSettings.ApiKey, sonarrSettings.FullUri); Log.Trace("Sonarr Add Result: "); @@ -65,7 +65,7 @@ namespace PlexRequests.UI.Helpers public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model) { - var result = SickrageApi.AddSeries(model.ProviderId, model.LatestTv, sickRageSettings.QualityProfile, + var result = SickrageApi.AddSeries(model.ProviderId, model.LatestTv, model.SeasonList, sickRageSettings.QualityProfile, sickRageSettings.ApiKey, sickRageSettings.FullUri); Log.Trace("SickRage Add Result: "); diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 7d1d0dcab..a9a5fd446 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -77,7 +77,7 @@ namespace PlexRequests.UI.Modules Get["movie/playing"] = parameters => CurrentlyPlayingMovies(); Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId); - Post["request/tv"] = parameters => RequestTvShow((int)Request.Form.tvId, (bool)Request.Form.latest); + Post["request/tv"] = parameters => RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons); } private TheMovieDbApi MovieApi { get; } private ICouchPotatoApi CouchPotatoApi { get; } @@ -259,7 +259,7 @@ namespace PlexRequests.UI.Modules /// The show identifier. /// if set to true [latest]. /// - private Response RequestTvShow(int showId, bool latest) + private Response RequestTvShow(int showId, string seasons) { if (RequestService.CheckRequest(showId)) { @@ -285,7 +285,7 @@ namespace PlexRequests.UI.Modules DateTime firstAir; DateTime.TryParse(showInfo.premiered, out firstAir); - + var latest = seasons == "latest"; var model = new RequestedModel { ProviderId = showInfo.externals?.thetvdb ?? 0, @@ -302,7 +302,12 @@ namespace PlexRequests.UI.Modules LatestTv = latest, ImdbId = showInfo.externals?.imdb ?? string.Empty }; - + var seasonsList = new List(); + if (seasons == "first") + { + seasonsList.Add(1); + } + model.SeasonList = seasonsList.ToArray(); var settings = PrService.GetSettings(); if (!settings.RequireApproval) @@ -357,7 +362,7 @@ namespace PlexRequests.UI.Modules private Response SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model) { - var result = SickrageApi.AddSeries(model.ProviderId, model.LatestTv, sickRageSettings.QualityProfile, + var result = SickrageApi.AddSeries(model.ProviderId, model.LatestTv, model.SeasonList, sickRageSettings.QualityProfile, sickRageSettings.ApiKey, sickRageSettings.FullUri); Log.Trace("SickRage Result: "); diff --git a/PlexRequests.UI/Views/Search/Index.cshtml b/PlexRequests.UI/Views/Search/Index.cshtml index 7e41c6b4d..553ac32d7 100644 --- a/PlexRequests.UI/Views/Search/Index.cshtml +++ b/PlexRequests.UI/Views/Search/Index.cshtml @@ -84,7 +84,7 @@
- + {{#if_eq type "movie"}} {{/if_eq}} @@ -96,7 +96,8 @@
{{/if_eq}}