changed IEmbyAvailabilityChecker to use IEnumberables + checking actor search against Emby content + PR feedback

pull/1178/head
smcpeck 8 years ago
parent c96ec2ef9d
commit 99e48f31fe

@ -161,15 +161,15 @@ namespace Ombi.Services.Jobs
return content.Where(x => x.Type == EmbyMediaType.Movie);
}
public bool IsMovieAvailable(EmbyContent[] embyMovies, string title, string year, string providerId)
public bool IsMovieAvailable(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId)
{
var movie = GetMovie(embyMovies, title, year, providerId);
return movie != null;
}
public EmbyContent GetMovie(EmbyContent[] embyMovies, string title, string year, string providerId)
public EmbyContent GetMovie(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId)
{
if (embyMovies.Length == 0)
if (embyMovies.Count() == 0)
{
return null;
}
@ -200,14 +200,14 @@ namespace Ombi.Services.Jobs
return content.Where(x => x.Type == EmbyMediaType.Series);
}
public bool IsTvShowAvailable(EmbyContent[] embyShows, string title, string year, string providerId, int[] seasons = null)
public bool IsTvShowAvailable(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId, int[] seasons = null)
{
var show = GetTvShow(embyShows, title, year, providerId, seasons);
return show != null;
}
public EmbyContent GetTvShow(EmbyContent[] embyShows, string title, string year, string providerId,
public EmbyContent GetTvShow(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId,
int[] seasons = null)
{
foreach (var show in embyShows)

@ -14,11 +14,11 @@ namespace Ombi.Services.Jobs
IEnumerable<EmbyContent> GetEmbyTvShows(IEnumerable<EmbyContent> content);
Task<IEnumerable<EmbyEpisodes>> GetEpisodes();
Task<IEnumerable<EmbyEpisodes>> GetEpisodes(int theTvDbId);
EmbyContent GetMovie(EmbyContent[] embyMovies, string title, string year, string providerId);
EmbyContent GetTvShow(EmbyContent[] embyShows, string title, string year, string providerId, int[] seasons = null);
EmbyContent GetMovie(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId);
EmbyContent GetTvShow(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId, int[] seasons = null);
bool IsEpisodeAvailable(string theTvDbId, int season, int episode);
bool IsMovieAvailable(EmbyContent[] embyMovies, string title, string year, string providerId);
bool IsTvShowAvailable(EmbyContent[] embyShows, string title, string year, string providerId, int[] seasons = null);
bool IsMovieAvailable(IEnumerable<EmbyContent> embyMovies, string title, string year, string providerId);
bool IsTvShowAvailable(IEnumerable<EmbyContent> embyShows, string title, string year, string providerId, int[] seasons = null);
void Start();
}
}

@ -187,6 +187,10 @@ namespace Ombi.UI.Modules
private long _plexMovieCacheTime = 0;
private IEnumerable<PlexContent> _plexMovies = null;
private long _embyMovieCacheTime = 0;
private IEnumerable<EmbyContent> _embyMovies = null;
private long _dbMovieCacheTime = 0;
private Dictionary<int, RequestedModel> _dbMovies = null;
@ -243,11 +247,15 @@ namespace Ombi.UI.Modules
private async Task<bool> AlreadyAvailable(int id, string title, string year)
{
await Task.Yield();
return IsMovieInCache(id, String.Empty) || PlexChecker.IsMovieAvailable(plexMovies(), title, year);
var plexSettings = await PlexService.GetSettingsAsync();
var embySettings = await EmbySettings.GetSettingsAsync();
return IsMovieInCache(id, String.Empty) ||
(plexSettings.Enable && PlexChecker.IsMovieAvailable(PlexMovies(), title, year)) ||
(embySettings.Enable && EmbyChecker.IsMovieAvailable(EmbyMovies(), title, year, String.Empty));
}
private IEnumerable<PlexContent> plexMovies()
private IEnumerable<PlexContent> PlexMovies()
{ long now = DateTime.Now.Ticks;
if(_plexMovies == null || (now - _plexMovieCacheTime) > 10000)
{
@ -259,6 +267,19 @@ namespace Ombi.UI.Modules
return _plexMovies;
}
private IEnumerable<EmbyContent> EmbyMovies()
{
long now = DateTime.Now.Ticks;
if (_embyMovies == null || (now - _embyMovieCacheTime) > 10000)
{
var content = EmbyContentRepository.GetAll();
_embyMovies = EmbyChecker.GetEmbyMovies(content);
_embyMovieCacheTime = now;
}
return _embyMovies;
}
private Response GetTvPoster(int theTvDbId)
{
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
@ -340,7 +361,7 @@ namespace Ombi.UI.Modules
return await TransformMovieResultsToResponse(apiMovies);
}
private async Task<Dictionary<int, RequestedModel>> requestedMovies()
private async Task<Dictionary<int, RequestedModel>> RequestedMovies()
{
long now = DateTime.Now.Ticks;
if (_dbMovies == null || (now - _dbMovieCacheTime) > 10000)
@ -360,7 +381,7 @@ namespace Ombi.UI.Modules
await Task.Yield();
var viewMovies = new List<SearchMovieViewModel>();
var counter = 0;
Dictionary<int, RequestedModel> dbMovies = await requestedMovies();
Dictionary<int, RequestedModel> dbMovies = await RequestedMovies();
foreach (var movie in movies)
{
var viewMovie = new SearchMovieViewModel

Loading…
Cancel
Save