mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 19:40:05 -07:00
Fixed an issue when Plex decideds to reuse the Plex Key for a different media item... #2038
Also made multiple serves more resilient when one of them fails
This commit is contained in:
parent
ecb77262dd
commit
04aee45446
1 changed files with 220 additions and 189 deletions
|
@ -93,7 +93,20 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
{
|
{
|
||||||
foreach (var servers in plexSettings.Servers ?? new List<PlexServers>())
|
foreach (var servers in plexSettings.Servers ?? new List<PlexServers>())
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Logger.LogInformation("Starting to cache the content on server {0}", servers.Name);
|
||||||
|
await ProcessServer(servers);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogWarning(LoggingEvents.PlexContentCacher, e, "Exception thrown when attempting to cache the Plex Content in server {0}", servers.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ProcessServer(PlexServers servers)
|
||||||
|
{
|
||||||
Logger.LogInformation("Getting all content from server {0}", servers.Name);
|
Logger.LogInformation("Getting all content from server {0}", servers.Name);
|
||||||
var allContent = await GetAllContent(servers);
|
var allContent = await GetAllContent(servers);
|
||||||
Logger.LogInformation("We found {0} items", allContent.Count);
|
Logger.LogInformation("We found {0} items", allContent.Count);
|
||||||
|
@ -128,10 +141,27 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
&& x.ReleaseYear == show.year.ToString()
|
&& x.ReleaseYear == show.year.ToString()
|
||||||
&& x.Type == PlexMediaTypeEntity.Show);
|
&& x.Type == PlexMediaTypeEntity.Show);
|
||||||
|
|
||||||
|
// Just double check the rating key, since this is our unique constraint
|
||||||
|
var existingKey = await Repo.GetByKey(show.ratingKey);
|
||||||
|
|
||||||
|
if (existingKey != null)
|
||||||
|
{
|
||||||
|
// Damn son.
|
||||||
|
// Let's check if they match up
|
||||||
|
var doesMatch = show.title.Equals(existingKey.Title,
|
||||||
|
StringComparison.CurrentCulture);
|
||||||
|
if (!doesMatch)
|
||||||
|
{
|
||||||
|
// Something fucked up on Plex at somepoint... Damn, rebuild of lib maybe?
|
||||||
|
// Lets delete the matching key
|
||||||
|
await Repo.Delete(existingKey);
|
||||||
|
existingKey = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (existingContent != null)
|
if (existingContent != null)
|
||||||
{
|
{
|
||||||
// Just check the key
|
// Just check the key
|
||||||
var existingKey = await Repo.GetByKey(show.ratingKey);
|
|
||||||
if (existingKey != null)
|
if (existingKey != null)
|
||||||
{
|
{
|
||||||
// The rating key is all good!
|
// The rating key is all good!
|
||||||
|
@ -155,7 +185,6 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
await Repo.SaveChangesAsync();
|
await Repo.SaveChangesAsync();
|
||||||
existingContent = null;
|
existingContent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// The ratingKey keeps changing...
|
// The ratingKey keeps changing...
|
||||||
//var existingContent = await Repo.GetByKey(show.ratingKey);
|
//var existingContent = await Repo.GetByKey(show.ratingKey);
|
||||||
|
@ -163,12 +192,14 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logger.LogInformation("We already have show {0} checking for new seasons", existingContent.Title);
|
Logger.LogInformation("We already have show {0} checking for new seasons",
|
||||||
|
existingContent.Title);
|
||||||
// Ok so we have it, let's check if there are any new seasons
|
// Ok so we have it, let's check if there are any new seasons
|
||||||
var itemAdded = false;
|
var itemAdded = false;
|
||||||
foreach (var season in seasonsContent)
|
foreach (var season in seasonsContent)
|
||||||
{
|
{
|
||||||
var seasonExists = existingContent.Seasons.FirstOrDefault(x => x.SeasonKey == season.SeasonKey);
|
var seasonExists =
|
||||||
|
existingContent.Seasons.FirstOrDefault(x => x.SeasonKey == season.SeasonKey);
|
||||||
|
|
||||||
if (seasonExists != null)
|
if (seasonExists != null)
|
||||||
{
|
{
|
||||||
|
@ -184,21 +215,23 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.LogError(LoggingEvents.PlexContentCacher, e, "Exception when adding new seasons to title {0}", existingContent.Title);
|
Logger.LogError(LoggingEvents.PlexContentCacher, e,
|
||||||
|
"Exception when adding new seasons to title {0}", existingContent.Title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
Logger.LogInformation("New show {0}, so add it", show.title);
|
Logger.LogInformation("New show {0}, so add it", show.title);
|
||||||
|
|
||||||
// Get the show metadata... This sucks since the `metadata` var contains all information about the show
|
// Get the show metadata... This sucks since the `metadata` var contains all information about the show
|
||||||
// But it does not contain the `guid` property that we need to pull out thetvdb id...
|
// But it does not contain the `guid` property that we need to pull out thetvdb id...
|
||||||
var showMetadata = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri,
|
var showMetadata = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri,
|
||||||
show.ratingKey);
|
show.ratingKey);
|
||||||
var providerIds = PlexHelper.GetProviderIdFromPlexGuid(showMetadata.MediaContainer.Metadata.FirstOrDefault().guid);
|
var providerIds =
|
||||||
|
PlexHelper.GetProviderIdFromPlexGuid(showMetadata.MediaContainer.Metadata.FirstOrDefault()
|
||||||
|
.guid);
|
||||||
|
|
||||||
var item = new PlexServerContent
|
var item = new PlexServerContent
|
||||||
{
|
{
|
||||||
|
@ -251,13 +284,12 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
item.Seasons.ToList().AddRange(seasonsContent);
|
item.Seasons.ToList().AddRange(seasonsContent);
|
||||||
|
|
||||||
contentToAdd.Add(item);
|
contentToAdd.Add(item);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.LogError(LoggingEvents.PlexContentCacher, e, "Exception when adding tv show {0}", show.title);
|
Logger.LogError(LoggingEvents.PlexContentCacher, e, "Exception when adding tv show {0}",
|
||||||
|
show.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,7 +353,8 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.LogError(LoggingEvents.PlexContentCacher, e, "Exception when adding new Movie {0}", movie.title);
|
Logger.LogError(LoggingEvents.PlexContentCacher, e, "Exception when adding new Movie {0}",
|
||||||
|
movie.title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,8 +369,6 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
{
|
{
|
||||||
await Repo.AddRange(contentToAdd);
|
await Repo.AddRange(contentToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue