diff --git a/Ombi.Services/Jobs/EmbyAvailabilityChecker.cs b/Ombi.Services/Jobs/EmbyAvailabilityChecker.cs index 166ed987a..da4a79212 100644 --- a/Ombi.Services/Jobs/EmbyAvailabilityChecker.cs +++ b/Ombi.Services/Jobs/EmbyAvailabilityChecker.cs @@ -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 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 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 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 embyShows, string title, string year, string providerId, int[] seasons = null) { foreach (var show in embyShows) diff --git a/Ombi.Services/Jobs/Interfaces/IEmbyAvailabilityChecker.cs b/Ombi.Services/Jobs/Interfaces/IEmbyAvailabilityChecker.cs index a954064e7..52e620118 100644 --- a/Ombi.Services/Jobs/Interfaces/IEmbyAvailabilityChecker.cs +++ b/Ombi.Services/Jobs/Interfaces/IEmbyAvailabilityChecker.cs @@ -14,11 +14,11 @@ namespace Ombi.Services.Jobs IEnumerable GetEmbyTvShows(IEnumerable content); Task> GetEpisodes(); Task> 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 embyMovies, string title, string year, string providerId); + EmbyContent GetTvShow(IEnumerable 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 embyMovies, string title, string year, string providerId); + bool IsTvShowAvailable(IEnumerable embyShows, string title, string year, string providerId, int[] seasons = null); void Start(); } } \ No newline at end of file diff --git a/Ombi.UI/Modules/SearchModule.cs b/Ombi.UI/Modules/SearchModule.cs index 230233d92..6e675b959 100644 --- a/Ombi.UI/Modules/SearchModule.cs +++ b/Ombi.UI/Modules/SearchModule.cs @@ -187,6 +187,10 @@ namespace Ombi.UI.Modules private long _plexMovieCacheTime = 0; private IEnumerable _plexMovies = null; + private long _embyMovieCacheTime = 0; + private IEnumerable _embyMovies = null; + + private long _dbMovieCacheTime = 0; private Dictionary _dbMovies = null; @@ -243,11 +247,15 @@ namespace Ombi.UI.Modules private async Task 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 plexMovies() + private IEnumerable PlexMovies() { long now = DateTime.Now.Ticks; if(_plexMovies == null || (now - _plexMovieCacheTime) > 10000) { @@ -259,6 +267,19 @@ namespace Ombi.UI.Modules return _plexMovies; } + private IEnumerable 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> requestedMovies() + private async Task> 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(); var counter = 0; - Dictionary dbMovies = await requestedMovies(); + Dictionary dbMovies = await RequestedMovies(); foreach (var movie in movies) { var viewMovie = new SearchMovieViewModel