mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
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
This commit is contained in:
parent
cd2026f297
commit
acac2c3675
4 changed files with 67 additions and 7 deletions
|
@ -66,8 +66,10 @@ namespace Ombi.Api.Sonarr
|
||||||
var request = new Request($"/api/series/{id}", baseUrl, HttpMethod.Get);
|
var request = new Request($"/api/series/{id}", baseUrl, HttpMethod.Get);
|
||||||
request.AddHeader("X-Api-Key", apiKey);
|
request.AddHeader("X-Api-Key", apiKey);
|
||||||
var result = await Api.Request<SonarrSeries>(request);
|
var result = await Api.Request<SonarrSeries>(request);
|
||||||
result.seasons.ToList().RemoveAt(0);
|
if (result?.seasons?.Length > 0)
|
||||||
|
{
|
||||||
|
result?.seasons?.ToList().RemoveAt(0);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,16 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
{
|
{
|
||||||
seriesEpisodes = plexEpisodes.Where(x => x.Series.TvDbId == tvDbId.ToString());
|
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 season in child.SeasonRequests)
|
||||||
{
|
{
|
||||||
foreach (var episode in season.Episodes)
|
foreach (var episode in season.Episodes)
|
||||||
|
|
|
@ -127,13 +127,32 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
&& x.ReleaseYear == show.year.ToString()
|
&& x.ReleaseYear == show.year.ToString()
|
||||||
&& x.Type == PlexMediaTypeEntity.Show);
|
&& x.Type == PlexMediaTypeEntity.Show);
|
||||||
|
|
||||||
if (existingContent == null)
|
if (existingContent != null)
|
||||||
{
|
{
|
||||||
// Just check the key
|
// Just check the key
|
||||||
var hasSameKey = await Repo.GetByKey(show.ratingKey);
|
var existingKey = await Repo.GetByKey(show.ratingKey);
|
||||||
if (hasSameKey != null)
|
if (existingKey != null)
|
||||||
{
|
{
|
||||||
existingContent = hasSameKey;
|
// The rating key is all good!
|
||||||
|
existingContent = existingKey;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 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)
|
foreach (var server in s.Servers)
|
||||||
{
|
{
|
||||||
await Cache(server);
|
await Cache(server);
|
||||||
BackgroundJob.Enqueue(() => _availabilityChecker.Start());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BackgroundJob.Enqueue(() => _availabilityChecker.Start());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -127,7 +128,10 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
private async Task ProcessEpsiodes(PlexContainer episodes)
|
private async Task ProcessEpsiodes(PlexContainer episodes)
|
||||||
{
|
{
|
||||||
var ep = new HashSet<PlexEpisode>();
|
var ep = new HashSet<PlexEpisode>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
foreach (var episode in episodes?.MediaContainer?.Metadata ?? new Metadata[]{})
|
foreach (var episode in episodes?.MediaContainer?.Metadata ?? new Metadata[]{})
|
||||||
{
|
{
|
||||||
// I don't think we need to get the metadata, we only need to get the metadata if we need the provider id (TheTvDbid). Why do we need it for episodes?
|
// I don't think we need to get the metadata, we only need to get the metadata if we need the provider id (TheTvDbid). Why do we need it for episodes?
|
||||||
|
@ -142,6 +146,25 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
// continue;
|
// 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
|
ep.Add(new PlexEpisode
|
||||||
{
|
{
|
||||||
EpisodeNumber = episode.index,
|
EpisodeNumber = episode.index,
|
||||||
|
@ -154,6 +177,12 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
}
|
}
|
||||||
|
|
||||||
await _repo.AddRange(ep);
|
await _repo.AddRange(ep);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool Validate(PlexServers settings)
|
private bool Validate(PlexServers settings)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue