pull/567/head
tidusjar 8 years ago
parent a46f5be1d3
commit 5816ddef98

@ -63,30 +63,18 @@ namespace PlexRequests.UI.Tests
} }
[Test] [Test]
public async Task HappyPathSendSeriesToSonarr() public async Task HappyPathSendSeriesToSonarrAllSeason()
{ {
var seriesResult = new SonarrAddSeries() { monitored = true }; var seriesResult = new SonarrAddSeries() { title = "ABC"};
SonarrMock.Setup(x => x.GetSeries(It.IsAny<string>(), It.IsAny<Uri>())).Returns(new List<Series>()); SonarrMock.Setup(x => x.GetSeries(It.IsAny<string>(), It.IsAny<Uri>())).Returns(F.Build<Series>().With(x => x.tvdbId, 1).With(x => x.title, "ABC").CreateMany().ToList());
SonarrMock.Setup(
x =>
x.AddSeries(
It.IsAny<int>(),
It.IsAny<string>(),
It.IsAny<int>(),
It.IsAny<bool>(),
It.IsAny<string>(),
It.IsAny<int>(),
It.IsAny<int[]>(),
It.IsAny<string>(),
It.IsAny<Uri>(),
It.IsAny<bool>(), It.IsAny<bool>())).Returns(seriesResult);
Sender = new TvSender(SonarrMock.Object, SickrageMock.Object); Sender = new TvSender(SonarrMock.Object, SickrageMock.Object);
var request = new RequestedModel(); var request = new RequestedModel {SeasonsRequested = "All", ProviderId = 1, Title = "ABC"};
var result = await Sender.SendToSonarr(GetSonarrSettings(), request); var result = await Sender.SendToSonarr(GetSonarrSettings(), request);
Assert.That(result, Is.EqualTo(seriesResult)); Assert.That(result.title, Is.EqualTo("ABC"));
SonarrMock.Verify(x => x.AddSeries(It.IsAny<int>(), SonarrMock.Verify(x => x.AddSeries(It.IsAny<int>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<int>(), It.IsAny<int>(),
@ -96,7 +84,7 @@ namespace PlexRequests.UI.Tests
It.IsAny<int[]>(), It.IsAny<int[]>(),
It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<Uri>(), It.IsAny<Uri>(),
true, It.IsAny<bool>()), Times.Once); true, It.IsAny<bool>()), Times.Never);
} }
[Test] [Test]

@ -74,6 +74,11 @@ namespace PlexRequests.UI.Helpers
var series = await GetSonarrSeries(sonarrSettings, model.ProviderId); var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
var requestAll = model.SeasonsRequested?.Equals("All", StringComparison.CurrentCultureIgnoreCase);
var first = model.SeasonsRequested?.Equals("First", StringComparison.CurrentCultureIgnoreCase);
var latest = model.SeasonsRequested?.Equals("Latest", StringComparison.CurrentCultureIgnoreCase);
var specificSeasonRequest = model.SeasonList?.Any();
if (episodeRequest) if (episodeRequest)
{ {
// Does series exist? // Does series exist?
@ -113,73 +118,67 @@ namespace PlexRequests.UI.Helpers
} }
// Series exists, don't need to add it // Series exists, don't need to add it
if (series != null) if (series == null)
{ {
var requestAll = model.SeasonsRequested.Equals("All", StringComparison.CurrentCultureIgnoreCase); // Set the series as monitored with a season count as 0 so it doesn't search for anything
var first = model.SeasonsRequested.Equals("First", StringComparison.CurrentCultureIgnoreCase); SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
var latest = model.SeasonsRequested.Equals("Latest", StringComparison.CurrentCultureIgnoreCase); sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, model.SeasonList, sonarrSettings.ApiKey,
sonarrSettings.FullUri);
if (model.SeasonList.Any()) await Task.Delay(TimeSpan.FromSeconds(1));
series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
}
if (requestAll ?? false)
{
// Monitor all seasons
foreach (var season in series.seasons)
{ {
// Monitor the seasons that we have chosen season.monitored = true;
foreach (var season in series.seasons)
{
if (model.SeasonList.Contains(season.seasonNumber))
{
season.monitored = true;
}
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
SonarrApi.SearchForSeason(series.id, season.seasonNumber, sonarrSettings.ApiKey, sonarrSettings.FullUri);
}
return new SonarrAddSeries { title = series.title }; // We have updated it
} }
if (requestAll) SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
{ SonarrApi.SearchForSeries(series.id, sonarrSettings.ApiKey, sonarrSettings.FullUri); // Search For all episodes!"
// Monitor all seasons return new SonarrAddSeries { title = series.title }; // We have updated it
foreach (var season in series.seasons) }
{
season.monitored = true;
}
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); if (first ?? false)
SonarrApi.SearchForSeries(series.id, sonarrSettings.ApiKey, sonarrSettings.FullUri); // Search For all episodes!" {
return new SonarrAddSeries { title = series.title }; // We have updated it var firstSeries = (series?.seasons?.OrderBy(x => x.seasonNumber)).FirstOrDefault(x => x.seasonNumber > 0) ?? new Season();
} firstSeries.monitored = true;
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
SonarrApi.SearchForSeason(series.id, firstSeries.seasonNumber, sonarrSettings.ApiKey,
sonarrSettings.FullUri);
return new SonarrAddSeries { title = series.title }; // We have updated it
}
if (first) if (latest ?? false)
{ {
var firstSeries = series?.seasons?.OrderBy(x => x.seasonNumber)?.FirstOrDefault() ?? new Season(); var lastSeries = series?.seasons?.OrderByDescending(x => x.seasonNumber)?.FirstOrDefault() ?? new Season();
firstSeries.monitored = true; lastSeries.monitored = true;
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
SonarrApi.SearchForSeason(series.id, firstSeries.seasonNumber, sonarrSettings.ApiKey, SonarrApi.SearchForSeason(series.id, lastSeries.seasonNumber, sonarrSettings.ApiKey,
sonarrSettings.FullUri); sonarrSettings.FullUri);
return new SonarrAddSeries { title = series.title }; // We have updated it return new SonarrAddSeries { title = series.title }; // We have updated it
} }
if (latest) if (specificSeasonRequest ?? false)
{
// Monitor the seasons that we have chosen
foreach (var season in series.seasons)
{ {
var lastSeries = series?.seasons?.OrderByDescending(x => x.seasonNumber)?.FirstOrDefault() ?? new Season(); if (model.SeasonList.Contains(season.seasonNumber))
lastSeries.monitored = true; {
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); season.monitored = true;
SonarrApi.SearchForSeason(series.id, lastSeries.seasonNumber, sonarrSettings.ApiKey, SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
sonarrSettings.FullUri); SonarrApi.SearchForSeason(series.id, season.seasonNumber, sonarrSettings.ApiKey, sonarrSettings.FullUri);
return new SonarrAddSeries { title = series.title }; // We have updated it }
} }
// Update the series in sonarr with the new monitored status
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
await RequestAllEpisodesInASeasonWithExistingSeries(model, series, sonarrSettings);
return new SonarrAddSeries { title = series.title }; // We have updated it return new SonarrAddSeries { title = series.title }; // We have updated it
} }
return null;
var result = SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
sonarrSettings.SeasonFolders, sonarrSettings.RootPath, model.SeasonCount, model.SeasonList, sonarrSettings.ApiKey,
sonarrSettings.FullUri, true, true);
return result;
} }
public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model) public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model)
@ -278,7 +277,7 @@ namespace PlexRequests.UI.Helpers
var tasks = new List<Task>(); var tasks = new List<Task>();
var requestedEpisodes = model.Episodes; var requestedEpisodes = model.Episodes;
foreach (var r in episodes) foreach (var r in episodes)
{ {
if (r.hasFile) // If it already has the file, there is no point in updating it if (r.hasFile) // If it already has the file, there is no point in updating it

@ -362,7 +362,6 @@ namespace PlexRequests.UI.Modules
viewT.Requested = true; viewT.Requested = true;
viewT.Episodes = dbt.Episodes.ToList(); viewT.Episodes = dbt.Episodes.ToList();
viewT.Approved = dbt.Approved; viewT.Approved = dbt.Approved;
viewT.Available = dbt.Available;
} }
if (sonarrCached.Contains(tvdbid) || sickRageCache.Contains(tvdbid)) // compare to the sonarr/sickrage db if (sonarrCached.Contains(tvdbid) || sickRageCache.Contains(tvdbid)) // compare to the sonarr/sickrage db
{ {

Loading…
Cancel
Save