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

@ -63,30 +63,18 @@ namespace PlexRequests.UI.Tests
}
[Test]
public async Task HappyPathSendSeriesToSonarr()
public async Task HappyPathSendSeriesToSonarrAllSeason()
{
var seriesResult = new SonarrAddSeries() { monitored = true };
SonarrMock.Setup(x => x.GetSeries(It.IsAny<string>(), It.IsAny<Uri>())).Returns(new List<Series>());
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);
var seriesResult = new SonarrAddSeries() { title = "ABC"};
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());
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);
Assert.That(result, Is.EqualTo(seriesResult));
Assert.That(result.title, Is.EqualTo("ABC"));
SonarrMock.Verify(x => x.AddSeries(It.IsAny<int>(),
It.IsAny<string>(),
It.IsAny<int>(),
@ -96,7 +84,7 @@ namespace PlexRequests.UI.Tests
It.IsAny<int[]>(),
It.IsAny<string>(),
It.IsAny<Uri>(),
true, It.IsAny<bool>()), Times.Once);
true, It.IsAny<bool>()), Times.Never);
}
[Test]

@ -74,6 +74,11 @@ namespace PlexRequests.UI.Helpers
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)
{
// Does series exist?
@ -113,73 +118,67 @@ namespace PlexRequests.UI.Helpers
}
// Series exists, don't need to add it
if (series != null)
if (series == null)
{
var requestAll = model.SeasonsRequested.Equals("All", StringComparison.CurrentCultureIgnoreCase);
var first = model.SeasonsRequested.Equals("First", StringComparison.CurrentCultureIgnoreCase);
var latest = model.SeasonsRequested.Equals("Latest", StringComparison.CurrentCultureIgnoreCase);
// Set the series as monitored with a season count as 0 so it doesn't search for anything
SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
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
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
season.monitored = true;
}
if (requestAll)
{
// Monitor all seasons
foreach (var season in series.seasons)
{
season.monitored = true;
}
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
SonarrApi.SearchForSeries(series.id, sonarrSettings.ApiKey, sonarrSettings.FullUri); // Search For all episodes!"
return new SonarrAddSeries { title = series.title }; // We have updated it
}
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
SonarrApi.SearchForSeries(series.id, sonarrSettings.ApiKey, sonarrSettings.FullUri); // Search For all episodes!"
return new SonarrAddSeries { title = series.title }; // We have updated it
}
if (first ?? false)
{
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)
{
var firstSeries = series?.seasons?.OrderBy(x => x.seasonNumber)?.FirstOrDefault() ?? 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 (latest ?? false)
{
var lastSeries = series?.seasons?.OrderByDescending(x => x.seasonNumber)?.FirstOrDefault() ?? new Season();
lastSeries.monitored = true;
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
SonarrApi.SearchForSeason(series.id, lastSeries.seasonNumber, sonarrSettings.ApiKey,
sonarrSettings.FullUri);
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();
lastSeries.monitored = true;
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
SonarrApi.SearchForSeason(series.id, lastSeries.seasonNumber, sonarrSettings.ApiKey,
sonarrSettings.FullUri);
return new SonarrAddSeries { title = series.title }; // We have updated it
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);
}
}
// 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
}
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;
return null;
}
public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model)
@ -278,7 +277,7 @@ namespace PlexRequests.UI.Helpers
var tasks = new List<Task>();
var requestedEpisodes = model.Episodes;
foreach (var r in episodes)
{
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.Episodes = dbt.Episodes.ToList();
viewT.Approved = dbt.Approved;
viewT.Available = dbt.Available;
}
if (sonarrCached.Contains(tvdbid) || sickRageCache.Contains(tvdbid)) // compare to the sonarr/sickrage db
{

Loading…
Cancel
Save