Skip to content

Commit

Permalink
Fixed #1048 #1081
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Feb 8, 2017
1 parent 3d3d3ff commit f74413f
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions Ombi.UI/Modules/SearchModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,51 +525,55 @@ private async Task<Response> ProcessShows(ShowSearchType type)

private async Task<List<SearchTvShowViewModel>> MapToTvModel(List<SearchTvShowViewModel> shows, PlexRequestSettings prSettings)
{

var plexSettings = await PlexService.GetSettingsAsync();
var embySettings = await EmbySettings.GetSettingsAsync();

var providerId = string.Empty;
// Get the requests
var allResults = await RequestService.GetAllAsync();
allResults = allResults.Where(x => x.Type == RequestType.TvShow);
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
var dbTv = distinctResults.ToDictionary(x => x.ProviderId);

// Check the external applications
var sonarrCached = SonarrCacher.QueuedIds().ToList();
var sickRageCache = SickRageCacher.QueuedIds(); // consider just merging sonarr/sickrage arrays
var dbTv = distinctResults.ToDictionary(x => x.ImdbId);

var content = PlexContentRepository.GetAll();
var plexTvShows = PlexChecker.GetPlexTvShows(content).ToList();
var plexTvShows = PlexChecker.GetPlexTvShows(content);
var embyContent = EmbyContentRepository.GetAll();
var embyCached = EmbyChecker.GetEmbyTvShows(embyContent).ToList();

foreach (var show in shows)
{
if (plexSettings.AdvancedSearch)

var providerId = show.Id.ToString();

if (embySettings.Enable)
{
providerId = show.Id.ToString();
var embyShow = EmbyChecker.GetTvShow(embyCached.ToArray(), show.SeriesName, show.FirstAired?.Substring(0, 4), providerId);
if (embyShow != null)
{
show.Available = true;
}
}

var plexShow = PlexChecker.GetTvShow(plexTvShows.ToArray(), show.SeriesName, show.FirstAired?.Substring(0, 4),
providerId);
if (plexShow != null)
if (plexSettings.Enable)
{
show.Available = true;
show.PlexUrl = plexShow.Url;
var plexShow = PlexChecker.GetTvShow(plexTvShows.ToArray(), show.SeriesName, show.FirstAired?.Substring(0, 4),
providerId);
if (plexShow != null)
{
show.Available = true;
show.PlexUrl = plexShow.Url;
}
}
else

if (show.ImdbId != null && !show.Available)
{
if (dbTv.ContainsKey(show.Id))
var imdbId = show.ImdbId;
if (dbTv.ContainsKey(imdbId))
{
var dbt = dbTv[show.Id];
var dbt = dbTv[imdbId];

show.Requested = true;
show.Episodes = dbt.Episodes.ToList();
show.Approved = dbt.Approved;
}
if (sonarrCached.Select(x => x.TvdbId).Contains(show.Id) || sickRageCache.Contains(show.Id))
// compare to the sonarr/sickrage db
{
show.Requested = true;
}
}
}
return shows;
Expand Down

0 comments on commit f74413f

Please sign in to comment.