mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 06:00:50 -07:00
Fixed #466
This commit is contained in:
parent
7fe82bb0af
commit
46a63f48c4
1 changed files with 74 additions and 29 deletions
|
@ -71,13 +71,11 @@ namespace PlexRequests.UI.Helpers
|
|||
int.TryParse(sonarrSettings.QualityProfile, out qualityProfile);
|
||||
}
|
||||
|
||||
|
||||
var seriesTask = GetSonarrSeries(sonarrSettings, model.ProviderId);
|
||||
var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
|
||||
|
||||
if (episodeRequest)
|
||||
{
|
||||
// Does series exist?
|
||||
var series = await seriesTask;
|
||||
if (series != null)
|
||||
{
|
||||
// Series Exists
|
||||
|
@ -85,8 +83,8 @@ namespace PlexRequests.UI.Helpers
|
|||
await RequestEpisodesWithExistingSeries(model, series, sonarrSettings);
|
||||
return new SonarrAddSeries {title = series.title};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
// Series doesn't exist, need to add it as unmonitored.
|
||||
var addResult = await Task.Run(() => SonarrApi.AddSeries(model.ProviderId, model.Title, qualityProfile,
|
||||
sonarrSettings.SeasonFolders, sonarrSettings.RootPath, 0, new int[0], sonarrSettings.ApiKey,
|
||||
|
@ -112,6 +110,22 @@ namespace PlexRequests.UI.Helpers
|
|||
|
||||
return addResult;
|
||||
}
|
||||
|
||||
if (series != null)
|
||||
{
|
||||
// Monitor the seasons that we have chosen
|
||||
foreach (var season in series.seasons)
|
||||
{
|
||||
if (model.SeasonList.Contains(season.seasonNumber))
|
||||
{
|
||||
season.monitored = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the series in sonarr with the new monitored status
|
||||
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||
await RequestAllEpisodesWithExistingSeries(model, series, sonarrSettings);
|
||||
return new SonarrAddSeries { title = series.title }; // We have updated it
|
||||
}
|
||||
|
||||
|
||||
|
@ -175,6 +189,37 @@ namespace PlexRequests.UI.Helpers
|
|||
|
||||
SonarrApi.SearchForEpisodes(internalEpisodeIds.ToArray(), sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||
}
|
||||
|
||||
internal async Task RequestAllEpisodesWithExistingSeries(RequestedModel model, Series selectedSeries, SonarrSettings sonarrSettings)
|
||||
{
|
||||
// Show Exists
|
||||
// Look up all episodes
|
||||
var ep = SonarrApi.GetEpisodes(selectedSeries.id.ToString(), sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||
var episodes = ep?.ToList() ?? new List<SonarrEpisodes>();
|
||||
|
||||
var internalEpisodeIds = new List<int>();
|
||||
var tasks = new List<Task>();
|
||||
foreach (var r in episodes)
|
||||
{
|
||||
if(r.monitored || r.hasFile) // If it's already montiored or has the file, there is no point in updating it
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Lookup the individual episode details
|
||||
var episodeInfo = SonarrApi.GetEpisode(r.id.ToString(), sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||
episodeInfo.monitored = true; // Set the episode to monitored
|
||||
|
||||
tasks.Add(Task.Run(() => SonarrApi.UpdateEpisode(episodeInfo, sonarrSettings.ApiKey,
|
||||
sonarrSettings.FullUri)));
|
||||
internalEpisodeIds.Add(r.id);
|
||||
}
|
||||
|
||||
await Task.WhenAll(tasks.ToArray());
|
||||
|
||||
SonarrApi.SearchForEpisodes(internalEpisodeIds.ToArray(), sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||
}
|
||||
|
||||
private async Task<Series> GetSonarrSeries(SonarrSettings sonarrSettings, int showId)
|
||||
{
|
||||
var task = await Task.Run(() => SonarrApi.GetSeries(sonarrSettings.ApiKey, sonarrSettings.FullUri)).ConfigureAwait(false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue