mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 07:46:05 -07:00
Fixed logo on reset password pages
fixed the run importer button on the user management settings Added root and qulaity profile selection for movies #1517 Added the Sonarr Cacher #1513 Refactored what we do to tv searches to use the rules engine Cache a few more things to speed some searches up
This commit is contained in:
parent
aad5c2a4bc
commit
9ae5ad0ecd
43 changed files with 1313 additions and 281 deletions
|
@ -15,11 +15,7 @@ using System.Linq;
|
|||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
using Ombi.Store.Repository.Requests;
|
||||
using Ombi.Store.Entities;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Helpers;
|
||||
|
@ -117,11 +113,7 @@ namespace Ombi.Core.Engine
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
var existingRequests = await GetTvRequests();
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
var embySettings = await EmbySettings.GetSettingsAsync();
|
||||
return await ProcessResult(mapped, existingRequests, plexSettings, embySettings);
|
||||
return await ProcessResult(mapped);
|
||||
}
|
||||
|
||||
public async Task<TreeNode<SearchTvShowViewModel>> GetShowInformationTreeNode(int tvdbid)
|
||||
|
@ -189,127 +181,21 @@ namespace Ombi.Core.Engine
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
private async Task<IEnumerable<SearchTvShowViewModel>> ProcessResults<T>(IEnumerable<T> items)
|
||||
{
|
||||
var existingRequests = await GetTvRequests();
|
||||
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
var embySettings = await EmbySettings.GetSettingsAsync();
|
||||
|
||||
var retVal = new List<SearchTvShowViewModel>();
|
||||
foreach (var tvMazeSearch in items)
|
||||
{
|
||||
var viewT = Mapper.Map<SearchTvShowViewModel>(tvMazeSearch);
|
||||
retVal.Add(await ProcessResult(viewT, existingRequests, plexSettings, embySettings));
|
||||
retVal.Add(await ProcessResult(viewT));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private async Task<SearchTvShowViewModel> ProcessResult(SearchTvShowViewModel item, Dictionary<int, TvRequests> existingRequests, PlexSettings plexSettings, EmbySettings embySettings)
|
||||
private async Task<SearchTvShowViewModel> ProcessResult(SearchTvShowViewModel item)
|
||||
{
|
||||
if (embySettings.Enable)
|
||||
{
|
||||
var content = await EmbyContentRepo.Get(item.Id.ToString());
|
||||
|
||||
if (content != null)
|
||||
{
|
||||
item.Available = true;
|
||||
}
|
||||
|
||||
// Let's go through the episodes now
|
||||
if (item.SeasonRequests.Any())
|
||||
{
|
||||
var allEpisodes = EmbyContentRepo.GetAllEpisodes().Include(x => x.Series);
|
||||
foreach (var season in item.SeasonRequests)
|
||||
{
|
||||
foreach (var episode in season.Episodes)
|
||||
{
|
||||
var epExists = await allEpisodes.FirstOrDefaultAsync(x =>
|
||||
x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && item.Id.ToString() == x.Series.ProviderId);
|
||||
if (epExists != null)
|
||||
{
|
||||
episode.Available = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (plexSettings.Enable)
|
||||
{
|
||||
var content = await PlexContentRepo.Get(item.Id.ToString());
|
||||
|
||||
if (content != null)
|
||||
{
|
||||
item.Available = true;
|
||||
item.PlexUrl = content.Url;
|
||||
}
|
||||
// Let's go through the episodes now
|
||||
if (item.SeasonRequests.Any())
|
||||
{
|
||||
var allEpisodes = PlexContentRepo.GetAllEpisodes();
|
||||
foreach (var season in item.SeasonRequests)
|
||||
{
|
||||
foreach (var episode in season.Episodes)
|
||||
{
|
||||
var epExists = await allEpisodes.FirstOrDefaultAsync(x =>
|
||||
x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.ProviderId == item.Id.ToString());
|
||||
if (epExists != null)
|
||||
{
|
||||
episode.Available = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item.SeasonRequests.Any() && item.SeasonRequests.All(x => x.Episodes.All(e => e.Approved)))
|
||||
{
|
||||
item.FullyAvailable = true;
|
||||
}
|
||||
|
||||
if (item.Id > 0)
|
||||
{
|
||||
var tvdbid = item.Id;
|
||||
if (existingRequests.ContainsKey(tvdbid))
|
||||
{
|
||||
var existingRequest = existingRequests[tvdbid];
|
||||
|
||||
item.Requested = true;
|
||||
item.Approved = existingRequest.ChildRequests.Any(x => x.Approved);
|
||||
|
||||
// Let's modify the seasonsrequested to reflect what we have requested...
|
||||
foreach (var season in item.SeasonRequests)
|
||||
{
|
||||
foreach (var existingRequestChildRequest in existingRequest.ChildRequests)
|
||||
{
|
||||
// Find the existing request season
|
||||
var existingSeason =
|
||||
existingRequestChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == season.SeasonNumber);
|
||||
if (existingSeason == null) continue;
|
||||
|
||||
foreach (var ep in existingSeason.Episodes)
|
||||
{
|
||||
// Find the episode from what we are searching
|
||||
var episodeSearching = season.Episodes.FirstOrDefault(x => x.EpisodeNumber == ep.EpisodeNumber);
|
||||
if (episodeSearching == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
episodeSearching.Requested = true;
|
||||
episodeSearching.Available = ep.Available;
|
||||
episodeSearching.Approved = ep.Season.ChildRequest.Approved;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO CHECK SONARR/RADARR
|
||||
//if (sonarrCached.Select(x => x.TvdbId).Contains(tvdbid) || sickRageCache.Contains(tvdbid))
|
||||
// // compare to the sonarr/sickrage db
|
||||
//{
|
||||
// item.Requested = true;
|
||||
//}
|
||||
}
|
||||
item.CustomId = item.Id.ToString();
|
||||
await RunSearchRules(item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue