mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
small bit of work
This commit is contained in:
parent
1350202993
commit
858171e92a
2 changed files with 108 additions and 48 deletions
|
@ -87,38 +87,109 @@ namespace Ombi.Core.Tv
|
||||||
|
|
||||||
if (requestAll ?? false)
|
if (requestAll ?? false)
|
||||||
{
|
{
|
||||||
return await ProcessSonarrRequestAll(sonarrSettings, model, qualityProfile, rootFolderPath);
|
return await ProcessSonarrRequestSeason(sonarrSettings, model, qualityProfile, rootFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first ?? false)
|
if (first ?? false)
|
||||||
{
|
{
|
||||||
return await ProcessSonarrRequestFirstSeason(sonarrSettings, model, qualityProfile, rootFolderPath);
|
return await ProcessSonarrRequestSeason(sonarrSettings, model, qualityProfile, rootFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (latest ?? false)
|
if (latest ?? false)
|
||||||
{
|
{
|
||||||
return await ProcessSonarrRequestLatestSeason(sonarrSettings, model, qualityProfile, rootFolderPath);
|
return await ProcessSonarrRequestSeason(sonarrSettings, model, qualityProfile, rootFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specificSeasonRequest ?? false)
|
if (specificSeasonRequest ?? false)
|
||||||
{
|
{
|
||||||
return await ProcessSonarrRequestSpecificSeason(sonarrSettings, model, qualityProfile, rootFolderPath);
|
return await ProcessSonarrRequestSeason(sonarrSettings, model, qualityProfile, rootFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<SonarrAddSeries> ProcessSonarrRequestSpecificSeason(SonarrSettings sonarrSettings, RequestedModel model, int qualityId, string rootFolderPath)
|
|
||||||
|
|
||||||
|
private async Task<SonarrAddSeries> ProcessSonarrRequestSeason(SonarrSettings sonarrSettings, RequestedModel model, int qualityId, string rootFolderPath)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// Does the series exist?
|
||||||
|
var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
|
||||||
|
if (series == null)
|
||||||
|
{
|
||||||
|
//WORKS
|
||||||
|
// Add the series
|
||||||
|
return AddSeries(sonarrSettings, model, rootFolderPath, qualityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<SonarrAddSeries> ProcessSonarrRequestLatestSeason(SonarrSettings sonarrSettings, RequestedModel model, int qualityId, string rootFolderPath)
|
// Also make sure the series is now monitored otherwise we won't search for it
|
||||||
|
series.monitored = true;
|
||||||
|
foreach (var seasons in series.seasons)
|
||||||
|
{
|
||||||
|
if (model.SeasonList.Any(x => x == seasons.seasonNumber))
|
||||||
|
{
|
||||||
|
seasons.monitored = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the update command
|
||||||
|
series = SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
|
SonarrApi.SearchForSeries(series.id, sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
|
return new SonarrAddSeries{title = series.title};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private async Task<SonarrAddSeries> ProcessSonarrEpisodeRequest(SonarrSettings sonarrSettings, RequestedModel model, int qualityId, string rootFolderPath)
|
||||||
{
|
{
|
||||||
// Does the series exist?
|
// Does the series exist?
|
||||||
|
|
||||||
var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
|
var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
|
||||||
if (series == null)
|
if (series == null)
|
||||||
|
{
|
||||||
|
var seriesToAdd = new SonarrAddSeries
|
||||||
|
{
|
||||||
|
seasonFolder = sonarrSettings.SeasonFolders,
|
||||||
|
title = model.Title,
|
||||||
|
qualityProfileId = qualityId,
|
||||||
|
tvdbId = model.ProviderId,
|
||||||
|
titleSlug = model.Title,
|
||||||
|
seasons = new List<Season>(),
|
||||||
|
rootFolderPath = rootFolderPath,
|
||||||
|
monitored = true, // Montior the series
|
||||||
|
images = new List<SonarrImage>(),
|
||||||
|
addOptions = new AddOptions
|
||||||
|
{
|
||||||
|
ignoreEpisodesWithFiles = true, // We don't really care about these
|
||||||
|
ignoreEpisodesWithoutFiles = true, // We do not want to grab random episodes missing
|
||||||
|
searchForMissingEpisodes = false // we want don't want to search for the missing episodes either
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 1; i <= model.SeasonCount; i++)
|
||||||
|
{
|
||||||
|
var season = new Season
|
||||||
|
{
|
||||||
|
seasonNumber = i,
|
||||||
|
monitored = false // Do not monitor any seasons
|
||||||
|
};
|
||||||
|
seriesToAdd.seasons.Add(season);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the series now
|
||||||
|
var result = SonarrApi.AddSeries(seriesToAdd, sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
|
|
||||||
|
await RequestEpisodesForSonarr(model, result.id, sonarrSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await RequestEpisodesForSonarr(model, series.id, sonarrSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SonarrAddSeries(){title = model.Title};
|
||||||
|
}
|
||||||
|
|
||||||
|
public SonarrAddSeries AddSeries(SonarrSettings sonarrSettings, RequestedModel model, string rootFolderPath, int qualityId)
|
||||||
{
|
{
|
||||||
//WORKS
|
//WORKS
|
||||||
// Add the series
|
// Add the series
|
||||||
|
@ -146,55 +217,44 @@ namespace Ombi.Core.Tv
|
||||||
var season = new Season
|
var season = new Season
|
||||||
{
|
{
|
||||||
seasonNumber = i,
|
seasonNumber = i,
|
||||||
// ReSharper disable once SimplifyConditionalTernaryExpression
|
monitored = model.SeasonList.Length == 0 || model.SeasonList.Any(x => x == i)
|
||||||
monitored = true ? model.SeasonList.Length == 0 || model.SeasonList.Any(x => x == i) : false
|
|
||||||
};
|
};
|
||||||
seriesToAdd.seasons.Add(season);
|
seriesToAdd.seasons.Add(season);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SonarrApi.AddSeries(seriesToAdd, sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
return SonarrApi.AddSeries(seriesToAdd, sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
private async Task RequestEpisodesForSonarr(RequestedModel model, int showId, SonarrSettings sonarrSettings)
|
||||||
{
|
{
|
||||||
// Mark the latest as monitored and search
|
// Now lookup all episodes
|
||||||
// Also make sure the series is now monitored otherwise we won't search for it
|
var ep = SonarrApi.GetEpisodes(showId.ToString(), sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
series.monitored = true;
|
var episodes = ep?.ToList() ?? new List<SonarrEpisodes>();
|
||||||
foreach (var seasons in series.seasons)
|
|
||||||
|
var internalEpisodeIds = new List<int>();
|
||||||
|
var tasks = new List<Task>();
|
||||||
|
foreach (var r in model.Episodes)
|
||||||
{
|
{
|
||||||
if (model.SeasonList.Any(x => x == seasons.seasonNumber))
|
// Match the episode and season number.
|
||||||
|
// If the episode is monitored we might not be searching for it.
|
||||||
|
var episode =
|
||||||
|
episodes.FirstOrDefault(
|
||||||
|
x => x.episodeNumber == r.EpisodeNumber && x.seasonNumber == r.SeasonNumber);
|
||||||
|
if (episode == null)
|
||||||
{
|
{
|
||||||
seasons.monitored = true;
|
continue;
|
||||||
}
|
}
|
||||||
|
var episodeInfo = SonarrApi.GetEpisode(episode.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(episode.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the update command
|
await Task.WhenAll(tasks.ToArray());
|
||||||
series = SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
|
||||||
SonarrApi.SearchForSeries(series.id, sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
|
||||||
return new SonarrAddSeries{title = series.title};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<SonarrAddSeries> ProcessSonarrRequestFirstSeason(SonarrSettings sonarrSettings, RequestedModel model, int qualityId, string rootFolderPath)
|
SonarrApi.SearchForEpisodes(internalEpisodeIds.ToArray(), sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<SonarrAddSeries> ProcessSonarrRequestAll(SonarrSettings sonarrSettings, RequestedModel model, int qualityId, string rootFolderPath)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<SonarrAddSeries> ProcessSonarrEpisodeRequest(SonarrSettings sonarrSettings, RequestedModel model, int qualityId, string rootFolderPath)
|
|
||||||
{
|
|
||||||
// Does the series exist?
|
|
||||||
|
|
||||||
var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
|
|
||||||
if (series == null)
|
|
||||||
{
|
|
||||||
// Add the series
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model)
|
public SickRageTvAdd SendToSickRage(SickRageSettings sickRageSettings, RequestedModel model)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue