|
|
|
@ -262,100 +262,122 @@ namespace Ombi.Schedule.Jobs.Plex
|
|
|
|
|
}
|
|
|
|
|
if (content.viewGroup.Equals(PlexMediaType.Movie.ToString(), StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
Logger.LogDebug("Processing Movies");
|
|
|
|
|
foreach (var movie in content?.Metadata ?? new Metadata[] { })
|
|
|
|
|
await MovieLoop(servers, content, contentToAdd, contentProcessed);
|
|
|
|
|
}
|
|
|
|
|
if (contentToAdd.Count > 500)
|
|
|
|
|
{
|
|
|
|
|
await Repo.AddRange(contentToAdd);
|
|
|
|
|
foreach (var c in contentToAdd)
|
|
|
|
|
{
|
|
|
|
|
// Let's check if we have this movie
|
|
|
|
|
contentProcessed.Add(c.Id, c.Key);
|
|
|
|
|
}
|
|
|
|
|
contentToAdd.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var existing = await Repo.GetFirstContentByCustom(x => x.Title == movie.title
|
|
|
|
|
&& x.ReleaseYear == movie.year.ToString()
|
|
|
|
|
&& x.Type == PlexMediaTypeEntity.Movie);
|
|
|
|
|
// The rating key keeps changing
|
|
|
|
|
//var existing = await Repo.GetByKey(movie.ratingKey);
|
|
|
|
|
if (existing != null)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogDebug("We already have movie {0}", movie.title);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (contentToAdd.Any())
|
|
|
|
|
{
|
|
|
|
|
await Repo.AddRange(contentToAdd);
|
|
|
|
|
foreach (var c in contentToAdd)
|
|
|
|
|
{
|
|
|
|
|
contentProcessed.Add(c.Id, c.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hasSameKey = await Repo.GetByKey(movie.ratingKey);
|
|
|
|
|
if (hasSameKey != null)
|
|
|
|
|
{
|
|
|
|
|
await Repo.Delete(hasSameKey);
|
|
|
|
|
}
|
|
|
|
|
retVal.Content = contentProcessed.Values;
|
|
|
|
|
retVal.Episodes = episodesProcessed;
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.LogDebug("Adding movie {0}", movie.title);
|
|
|
|
|
var guids = new List<string>();
|
|
|
|
|
if (!movie.Guid.Any())
|
|
|
|
|
{
|
|
|
|
|
var metaData = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri,
|
|
|
|
|
movie.ratingKey);
|
|
|
|
|
public async Task MovieLoop(PlexServers servers, Mediacontainer content, HashSet<PlexServerContent> contentToAdd,
|
|
|
|
|
Dictionary<int, int> contentProcessed)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogDebug("Processing Movies");
|
|
|
|
|
foreach (var movie in content?.Metadata ?? new Metadata[] { })
|
|
|
|
|
{
|
|
|
|
|
// Let's check if we have this movie
|
|
|
|
|
|
|
|
|
|
var meta = metaData.MediaContainer.Metadata.FirstOrDefault();
|
|
|
|
|
guids.Add(meta.guid);
|
|
|
|
|
if (meta.Guid != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var g in meta.Guid)
|
|
|
|
|
{
|
|
|
|
|
guids.Add(g.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Currently a Plex Pass feature only
|
|
|
|
|
foreach (var g in movie.Guid)
|
|
|
|
|
{
|
|
|
|
|
guids.Add(g.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var existing = await Repo.GetFirstContentByCustom(x => x.Title == movie.title
|
|
|
|
|
&& x.ReleaseYear == movie.year.ToString()
|
|
|
|
|
&& x.Type == PlexMediaTypeEntity.Movie);
|
|
|
|
|
// The rating key keeps changing
|
|
|
|
|
//var existing = await Repo.GetByKey(movie.ratingKey);
|
|
|
|
|
if (existing != null)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogDebug("We already have movie {0}", movie.title);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var providerIds = PlexHelper.GetProviderIdsFromMetadata(guids.ToArray());
|
|
|
|
|
var hasSameKey = await Repo.GetByKey(movie.ratingKey);
|
|
|
|
|
if (hasSameKey != null)
|
|
|
|
|
{
|
|
|
|
|
await Repo.Delete(hasSameKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var item = new PlexServerContent
|
|
|
|
|
{
|
|
|
|
|
AddedAt = DateTime.Now,
|
|
|
|
|
Key = movie.ratingKey,
|
|
|
|
|
ReleaseYear = movie.year.ToString(),
|
|
|
|
|
Type = PlexMediaTypeEntity.Movie,
|
|
|
|
|
Title = movie.title,
|
|
|
|
|
Url = PlexHelper.GetPlexMediaUrl(servers.MachineIdentifier, movie.ratingKey),
|
|
|
|
|
Seasons = new List<PlexSeasonsContent>(),
|
|
|
|
|
Quality = movie.Media?.FirstOrDefault()?.videoResolution ?? string.Empty
|
|
|
|
|
};
|
|
|
|
|
if (providerIds.ImdbId.HasValue())
|
|
|
|
|
{
|
|
|
|
|
item.ImdbId = providerIds.ImdbId;
|
|
|
|
|
}
|
|
|
|
|
if (providerIds.TheMovieDb.HasValue())
|
|
|
|
|
{
|
|
|
|
|
item.TheMovieDbId = providerIds.TheMovieDb;
|
|
|
|
|
}
|
|
|
|
|
if (providerIds.TheTvDb.HasValue())
|
|
|
|
|
Logger.LogDebug("Adding movie {0}", movie.title);
|
|
|
|
|
var guids = new List<string>();
|
|
|
|
|
if (!movie.Guid.Any())
|
|
|
|
|
{
|
|
|
|
|
var metaData = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri,
|
|
|
|
|
movie.ratingKey);
|
|
|
|
|
|
|
|
|
|
var meta = metaData.MediaContainer.Metadata.FirstOrDefault();
|
|
|
|
|
guids.Add(meta.guid);
|
|
|
|
|
if (meta.Guid != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var g in meta.Guid)
|
|
|
|
|
{
|
|
|
|
|
item.TvDbId = providerIds.TheTvDb;
|
|
|
|
|
guids.Add(g.Id);
|
|
|
|
|
}
|
|
|
|
|
contentToAdd.Add(item);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Currently a Plex Pass feature only
|
|
|
|
|
foreach (var g in movie.Guid)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogError(LoggingEvents.PlexContentCacher, e, "Exception when adding new Movie {0}",
|
|
|
|
|
movie.title);
|
|
|
|
|
guids.Add(g.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (contentToAdd.Count > 500)
|
|
|
|
|
{
|
|
|
|
|
await Repo.AddRange(contentToAdd);
|
|
|
|
|
foreach (var c in contentToAdd)
|
|
|
|
|
{
|
|
|
|
|
contentProcessed.Add(c.Id, c.Key);
|
|
|
|
|
}
|
|
|
|
|
contentToAdd.Clear();
|
|
|
|
|
}
|
|
|
|
|
var providerIds = PlexHelper.GetProviderIdsFromMetadata(guids.ToArray());
|
|
|
|
|
|
|
|
|
|
var item = new PlexServerContent
|
|
|
|
|
{
|
|
|
|
|
AddedAt = DateTime.Now,
|
|
|
|
|
Key = movie.ratingKey,
|
|
|
|
|
ReleaseYear = movie.year.ToString(),
|
|
|
|
|
Type = PlexMediaTypeEntity.Movie,
|
|
|
|
|
Title = movie.title,
|
|
|
|
|
Url = PlexHelper.GetPlexMediaUrl(servers.MachineIdentifier, movie.ratingKey),
|
|
|
|
|
Seasons = new List<PlexSeasonsContent>(),
|
|
|
|
|
Quality = movie.Media?.FirstOrDefault()?.videoResolution ?? string.Empty
|
|
|
|
|
};
|
|
|
|
|
if (providerIds.ImdbId.HasValue())
|
|
|
|
|
{
|
|
|
|
|
item.ImdbId = providerIds.ImdbId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (providerIds.TheMovieDb.HasValue())
|
|
|
|
|
{
|
|
|
|
|
item.TheMovieDbId = providerIds.TheMovieDb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (providerIds.TheTvDb.HasValue())
|
|
|
|
|
{
|
|
|
|
|
item.TvDbId = providerIds.TheTvDb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contentToAdd.Add(item);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogError(LoggingEvents.PlexContentCacher, e, "Exception when adding new Movie {0}",
|
|
|
|
|
movie.title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (contentToAdd.Count > 500)
|
|
|
|
|
{
|
|
|
|
|
await Repo.AddRange(contentToAdd);
|
|
|
|
@ -363,22 +385,10 @@ namespace Ombi.Schedule.Jobs.Plex
|
|
|
|
|
{
|
|
|
|
|
contentProcessed.Add(c.Id, c.Key);
|
|
|
|
|
}
|
|
|
|
|
contentToAdd.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (contentToAdd.Any())
|
|
|
|
|
{
|
|
|
|
|
await Repo.AddRange(contentToAdd);
|
|
|
|
|
foreach (var c in contentToAdd)
|
|
|
|
|
{
|
|
|
|
|
contentProcessed.Add(c.Id, c.Key);
|
|
|
|
|
contentToAdd.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retVal.Content = contentProcessed.Values;
|
|
|
|
|
retVal.Episodes = episodesProcessed;
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ProcessTvShow(PlexServers servers, Metadata show, HashSet<PlexServerContent> contentToAdd, Dictionary<int, int> contentProcessed)
|
|
|
|
|