|
|
@ -116,6 +116,7 @@ namespace Ombi.UI.Modules
|
|
|
|
Get["SearchIndex", "/", true] = async (x, ct) => await RequestLoad();
|
|
|
|
Get["SearchIndex", "/", true] = async (x, ct) => await RequestLoad();
|
|
|
|
|
|
|
|
|
|
|
|
Get["actor/{searchTerm}", true] = async (x, ct) => await SearchActor((string)x.searchTerm);
|
|
|
|
Get["actor/{searchTerm}", true] = async (x, ct) => await SearchActor((string)x.searchTerm);
|
|
|
|
|
|
|
|
Get["actor/new/{searchTerm}", true] = async (x, ct) => await SearchActor((string)x.searchTerm, true);
|
|
|
|
Get["movie/{searchTerm}", true] = async (x, ct) => await SearchMovie((string)x.searchTerm);
|
|
|
|
Get["movie/{searchTerm}", true] = async (x, ct) => await SearchMovie((string)x.searchTerm);
|
|
|
|
Get["tv/{searchTerm}", true] = async (x, ct) => await SearchTvShow((string)x.searchTerm);
|
|
|
|
Get["tv/{searchTerm}", true] = async (x, ct) => await SearchTvShow((string)x.searchTerm);
|
|
|
|
Get["music/{searchTerm}", true] = async (x, ct) => await SearchAlbum((string)x.searchTerm);
|
|
|
|
Get["music/{searchTerm}", true] = async (x, ct) => await SearchAlbum((string)x.searchTerm);
|
|
|
@ -173,6 +174,8 @@ namespace Ombi.UI.Modules
|
|
|
|
private IRadarrCacher RadarrCacher { get; }
|
|
|
|
private IRadarrCacher RadarrCacher { get; }
|
|
|
|
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
|
|
|
|
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
private IEnumerable<PlexContent> _plexMovies = null;
|
|
|
|
|
|
|
|
private Dictionary<int, RequestedModel> _dbMovies = null;
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<Negotiator> RequestLoad()
|
|
|
|
private async Task<Negotiator> RequestLoad()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -216,6 +219,29 @@ namespace Ombi.UI.Modules
|
|
|
|
return await TransformMovieResultsToResponse(movies);
|
|
|
|
return await TransformMovieResultsToResponse(movies);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<Response> SearchActor(string searchTerm, bool filterExisting)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var movies = TransformMovieListToMovieResultList(await MovieApi.SearchActor(searchTerm, AlreadyAvailable).ConfigureAwait(false));
|
|
|
|
|
|
|
|
return await TransformMovieResultsToResponse(movies);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<bool> AlreadyAvailable(int id, string title, string year)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
return IsMovieInCache(id, String.Empty) || Checker.IsMovieAvailable(plexMovies(), title, year);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<PlexContent> plexMovies()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(_plexMovies == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var content = PlexContentRepository.GetAll();
|
|
|
|
|
|
|
|
_plexMovies = Checker.GetPlexMovies(content);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return _plexMovies;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Response GetTvPoster(int theTvDbId)
|
|
|
|
private Response GetTvPoster(int theTvDbId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
|
|
|
var result = TvApi.ShowLookupByTheTvDbId(theTvDbId);
|
|
|
@ -297,22 +323,25 @@ namespace Ombi.UI.Modules
|
|
|
|
return await TransformMovieResultsToResponse(apiMovies);
|
|
|
|
return await TransformMovieResultsToResponse(apiMovies);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<Response> TransformMovieResultsToResponse(List<MovieResult> movies)
|
|
|
|
private async Task<Dictionary<int, RequestedModel>> requestedMovies()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_dbMovies == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var allResults = await RequestService.GetAllAsync();
|
|
|
|
var allResults = await RequestService.GetAllAsync();
|
|
|
|
allResults = allResults.Where(x => x.Type == RequestType.Movie);
|
|
|
|
allResults = allResults.Where(x => x.Type == RequestType.Movie);
|
|
|
|
|
|
|
|
|
|
|
|
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
|
|
|
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
|
|
|
var dbMovies = distinctResults.ToDictionary(x => x.ProviderId);
|
|
|
|
_dbMovies = distinctResults.ToDictionary(x => x.ProviderId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return _dbMovies;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var cpCached = CpCacher.QueuedIds();
|
|
|
|
private async Task<Response> TransformMovieResultsToResponse(List<MovieResult> movies)
|
|
|
|
var watcherCached = WatcherCacher.QueuedIds();
|
|
|
|
{
|
|
|
|
var radarrCached = RadarrCacher.QueuedIds();
|
|
|
|
await Task.Yield();
|
|
|
|
var content = PlexContentRepository.GetAll();
|
|
|
|
|
|
|
|
var plexMovies = Checker.GetPlexMovies(content);
|
|
|
|
|
|
|
|
var viewMovies = new List<SearchMovieViewModel>();
|
|
|
|
var viewMovies = new List<SearchMovieViewModel>();
|
|
|
|
var counter = 0;
|
|
|
|
var counter = 0;
|
|
|
|
|
|
|
|
Dictionary<int, RequestedModel> dbMovies = await requestedMovies();
|
|
|
|
foreach (var movie in movies)
|
|
|
|
foreach (var movie in movies)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var viewMovie = new SearchMovieViewModel
|
|
|
|
var viewMovie = new SearchMovieViewModel
|
|
|
@ -353,10 +382,8 @@ namespace Ombi.UI.Modules
|
|
|
|
counter++;
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var canSee = CanUserSeeThisRequest(viewMovie.Id, Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests), await requestedMovies());
|
|
|
|
var canSee = CanUserSeeThisRequest(viewMovie.Id, Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests), dbMovies);
|
|
|
|
var plexMovie = Checker.GetMovie(plexMovies(), movie.Title, movie.ReleaseDate?.Year.ToString(), imdbId);
|
|
|
|
var plexMovie = Checker.GetMovie(plexMovies.ToArray(), movie.Title, movie.ReleaseDate?.Year.ToString(),
|
|
|
|
|
|
|
|
imdbId);
|
|
|
|
|
|
|
|
if (plexMovie != null)
|
|
|
|
if (plexMovie != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
viewMovie.Available = true;
|
|
|
|
viewMovie.Available = true;
|
|
|
@ -370,26 +397,29 @@ namespace Ombi.UI.Modules
|
|
|
|
viewMovie.Approved = dbm.Approved;
|
|
|
|
viewMovie.Approved = dbm.Approved;
|
|
|
|
viewMovie.Available = dbm.Available;
|
|
|
|
viewMovie.Available = dbm.Available;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cpCached.Contains(movie.Id) && canSee) // compare to the couchpotato db
|
|
|
|
else if (canSee)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
viewMovie.Approved = true;
|
|
|
|
bool exists = IsMovieInCache(movie, imdbId);
|
|
|
|
viewMovie.Requested = true;
|
|
|
|
viewMovie.Approved = exists;
|
|
|
|
}
|
|
|
|
viewMovie.Requested = exists;
|
|
|
|
else if (watcherCached.Contains(imdbId) && canSee) // compare to the watcher db
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
viewMovie.Approved = true;
|
|
|
|
|
|
|
|
viewMovie.Requested = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (radarrCached.Contains(movie.Id) && canSee)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
viewMovie.Approved = true;
|
|
|
|
|
|
|
|
viewMovie.Requested = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
viewMovies.Add(viewMovie);
|
|
|
|
viewMovies.Add(viewMovie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Response.AsJson(viewMovies);
|
|
|
|
return Response.AsJson(viewMovies);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsMovieInCache(MovieResult movie, string imdbId)
|
|
|
|
|
|
|
|
{ int id = movie.Id;
|
|
|
|
|
|
|
|
return IsMovieInCache(id, imdbId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsMovieInCache(int id, string imdbId)
|
|
|
|
|
|
|
|
{ var cpCached = CpCacher.QueuedIds();
|
|
|
|
|
|
|
|
var watcherCached = WatcherCacher.QueuedIds();
|
|
|
|
|
|
|
|
var radarrCached = RadarrCacher.QueuedIds();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cpCached.Contains(id) || watcherCached.Contains(imdbId) || radarrCached.Contains(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool CanUserSeeThisRequest(int movieId, bool usersCanViewOnlyOwnRequests,
|
|
|
|
private bool CanUserSeeThisRequest(int movieId, bool usersCanViewOnlyOwnRequests,
|
|
|
|