Quick change to the Emby Availability rule to make it in line slightly with the Plex one. #1950

pull/1959/head
Jamie 7 years ago
parent 6227e11543
commit c3c85b0ae0

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Models.Search;
using Ombi.Core.Rule.Interfaces;
using Ombi.Helpers;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
@ -20,35 +21,48 @@ namespace Ombi.Core.Rule.Rules.Search
public async Task<RuleResult> Execute(SearchViewModel obj)
{
EmbyContent item = null;
if (obj.Type == RequestType.Movie)
if (obj.ImdbId.HasValue())
{
item = await EmbyContentRepository.Get(obj.ImdbId);
}
if (item == null)
{
if (obj.TheMovieDbId.HasValue())
{
item = await EmbyContentRepository.Get(obj.TheMovieDbId);
}
}
else
if (item == null)
{
if (obj.TheTvDbId.HasValue())
{
item = await EmbyContentRepository.Get(obj.TheTvDbId);
}
}
}
if (item != null)
{
obj.Available = true;
if (obj.Type == RequestType.TvShow)
{
var searchResult = (SearchTvShowViewModel)obj;
var search = (SearchTvShowViewModel)obj;
// Let's go through the episodes now
if (searchResult.SeasonRequests.Any())
if (search.SeasonRequests.Any())
{
var allEpisodes = EmbyContentRepository.GetAllEpisodes().Include(x => x.Series);
foreach (var season in searchResult.SeasonRequests)
foreach (var season in search.SeasonRequests)
{
foreach (var episode in season.Episodes)
{
var epExists = await allEpisodes.FirstOrDefaultAsync(x =>
x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && item.ProviderId.ToString() == searchResult.Id.ToString());
EmbyEpisode epExists = null;
epExists = await allEpisodes.FirstOrDefaultAsync(x =>
x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber &&
x.Series.ProviderId == item.ProviderId.ToString());
if (epExists != null)
{
episode.Available = true;

Loading…
Cancel
Save