Merge pull request #83 from shiitake/dev

Fixes issue #62 and #68
This commit is contained in:
Jamie 2016-03-24 19:08:32 +00:00
commit 47c0c0daf0
15 changed files with 151 additions and 59 deletions

View file

@ -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, int seasonCount, int[] seasons,
string apiKey, Uri baseUrl)
{
var json = MockApiData.Sonarr_AddSeriesResult;

View file

@ -28,9 +28,11 @@
#endregion
using System;
using System.Linq;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.SickRage;
using PlexRequests.Helpers;
using RestSharp;
namespace PlexRequests.Api
@ -47,13 +49,11 @@ namespace PlexRequests.Api
private ApiRequest Api { get; }
public SickRageTvAdd AddSeries(int tvdbId, bool latest, string quality, string apiKey,
public SickRageTvAdd AddSeries(int tvdbId, int seasonCount, int[] seasons, string quality, string apiKey,
Uri baseUrl)
{
string status;
var futureStatus = SickRageStatus.Wanted;
status = latest ? SickRageStatus.Skipped : SickRageStatus.Wanted;
var futureStatus = seasons.Length > 0 && !seasons.Any(x => x == seasonCount) ? SickRageStatus.Skipped : SickRageStatus.Wanted;
var status = seasons.Length > 0 ? SickRageStatus.Skipped : SickRageStatus.Wanted;
var request = new RestRequest
{
@ -71,6 +71,17 @@ namespace PlexRequests.Api
var obj = Api.Execute<SickRageTvAdd>(request, baseUrl);
if (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 +98,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<SickRageTvAdd>(request, baseUrl);
return obj;
}
}
}

View file

@ -26,7 +26,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Sonarr;
@ -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, int seasonCount, int[] seasons, string apiKey, Uri baseUrl)
{
var request = new RestRequest
@ -64,24 +64,28 @@ namespace PlexRequests.Api
};
var options = new SonarrAddSeries();
if (episodes)
{
options.addOptions = new AddOptions
{
ignoreEpisodesWithFiles = true,
ignoreEpisodesWithoutFiles = true,
searchForMissingEpisodes = false
};
}
else
{
options.addOptions = new AddOptions
{
ignoreEpisodesWithFiles = false,
searchForMissingEpisodes = true,
ignoreEpisodesWithoutFiles = false
};
}
//I'm fairly certain we won't need this logic anymore since we're manually adding the seasons
//if (seasons.Length == 0)
//{
// options.addOptions = new AddOptions
// {
// ignoreEpisodesWithFiles = true,
// ignoreEpisodesWithoutFiles = true,
// searchForMissingEpisodes = false
// };
//}
//else
//{
// options.addOptions = new AddOptions
// {
// ignoreEpisodesWithFiles = false,
// ignoreEpisodesWithoutFiles = false,
// searchForMissingEpisodes = true
// };
//}
options.seasonFolder = seasonFolders;
options.title = title;
options.qualityProfileId = qualityId;
@ -90,6 +94,15 @@ namespace PlexRequests.Api
options.seasons = new List<Season>();
options.rootFolderPath = rootPath;
for (var i = 1; i <= seasonCount; i++)
{
var season = new Season
{
seasonNumber = i,
monitored = seasons.Length == 0 || seasons.Any(x => x == i)
};
options.seasons.Add(season);
}
request.AddHeader("X-Api-Key", apiKey);
request.AddJsonBody(options);

View file

@ -26,7 +26,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using PlexRequests.Api.Models.Tv;
@ -79,7 +79,25 @@ namespace PlexRequests.Api
request.AddUrlSegment("id", theTvDbId.ToString());
request.AddHeader("Content-Type", "application/json");
return Api.Execute<TvMazeShow>(request, new Uri(Uri));
var obj = Api.Execute<TvMazeShow>(request, new Uri(Uri));
obj.seasonCount = GetSeasonCount(obj.id);
return obj;
}
public int GetSeasonCount(int id)
{
var request = new RestRequest
{
Method = Method.GET,
Resource = "shows/{id}/seasons"
};
request.AddUrlSegment("id", id.ToString());
request.AddHeader("Content-Type", "application/json");
var obj = Api.Execute<List<TvMazeSeasons>>(request, new Uri(Uri));
var seasons = obj.Select(x => x.number > 0);
return seasons.Count();
}
}