Try and fuzzy match the title and release if we cannot get the tvdb id or imdbid (depends on the media agents in Plex) #1951

Also fixed #1995
pull/2052/head
tidusjar 7 years ago
parent cd2026f297
commit acac2c3675

@ -66,8 +66,10 @@ namespace Ombi.Api.Sonarr
var request = new Request($"/api/series/{id}", baseUrl, HttpMethod.Get);
request.AddHeader("X-Api-Key", apiKey);
var result = await Api.Request<SonarrSeries>(request);
result.seasons.ToList().RemoveAt(0);
if (result?.seasons?.Length > 0)
{
result?.seasons?.ToList().RemoveAt(0);
}
return result;
}

@ -67,6 +67,16 @@ namespace Ombi.Schedule.Jobs.Plex
{
seriesEpisodes = plexEpisodes.Where(x => x.Series.TvDbId == tvDbId.ToString());
}
if (!seriesEpisodes.Any())
{
// Let's try and match the series by name
seriesEpisodes = plexEpisodes.Where(x =>
x.Series.Title.Equals(child.Title, StringComparison.CurrentCultureIgnoreCase) &&
x.Series.ReleaseYear == child.ParentRequest.ReleaseDate.Year.ToString());
}
foreach (var season in child.SeasonRequests)
{
foreach (var episode in season.Episodes)

@ -127,13 +127,32 @@ namespace Ombi.Schedule.Jobs.Plex
&& x.ReleaseYear == show.year.ToString()
&& x.Type == PlexMediaTypeEntity.Show);
if (existingContent == null)
if (existingContent != null)
{
// Just check the key
var hasSameKey = await Repo.GetByKey(show.ratingKey);
if (hasSameKey != null)
var existingKey = await Repo.GetByKey(show.ratingKey);
if (existingKey != null)
{
// The rating key is all good!
existingContent = existingKey;
}
else
{
existingContent = hasSameKey;
// This means the rating key has changed somehow.
// We need to reset the correct keys
var oldKey = existingContent.Key;
existingContent.Key = show.ratingKey;
// Because we have changed the rating key, we need to change all children too
var episodeToChange = Repo.GetAllEpisodes().Where(x => x.GrandparentKey == oldKey);
if (episodeToChange.Any())
{
foreach (var e in episodeToChange)
{
e.GrandparentKey = existingContent.Key;
}
}
await Repo.SaveChangesAsync();
}
}

@ -48,8 +48,9 @@ namespace Ombi.Schedule.Jobs.Plex
foreach (var server in s.Servers)
{
await Cache(server);
BackgroundJob.Enqueue(() => _availabilityChecker.Start());
}
BackgroundJob.Enqueue(() => _availabilityChecker.Start());
}
catch (Exception e)
{
@ -127,6 +128,9 @@ namespace Ombi.Schedule.Jobs.Plex
private async Task ProcessEpsiodes(PlexContainer episodes)
{
var ep = new HashSet<PlexEpisode>();
try
{
foreach (var episode in episodes?.MediaContainer?.Metadata ?? new Metadata[]{})
{
@ -142,6 +146,25 @@ namespace Ombi.Schedule.Jobs.Plex
// continue;
//}
// Let's check if we have the parent
var seriesExists = await _repo.GetByKey(episode.grandparentRatingKey);
if (seriesExists == null)
{
// Ok let's try and match it to a title. TODO (This is experimental)
var seriesMatch = await _repo.GetAll().FirstOrDefaultAsync(x =>
x.Title.Equals(episode.grandparentTitle, StringComparison.CurrentCultureIgnoreCase));
if (seriesMatch == null)
{
_log.LogWarning(
"The episode title {0} we cannot find the parent series. The episode grandparentKey = {1}, grandparentTitle = {2}",
episode.title, episode.grandparentRatingKey, episode.grandparentTitle);
continue;
}
// Set the rating key to the correct one
episode.grandparentRatingKey = seriesMatch.Key;
}
ep.Add(new PlexEpisode
{
EpisodeNumber = episode.index,
@ -154,6 +177,12 @@ namespace Ombi.Schedule.Jobs.Plex
}
await _repo.AddRange(ep);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
private bool Validate(PlexServers settings)

Loading…
Cancel
Save