fix(metadata): improved the metadata job to also lookup the media in Plex to see if it has any more uptodate metadata

pull/4554/head
tidusjar 3 years ago
parent 9cdd6f41cd
commit 83d1a15cc9

@ -180,6 +180,8 @@ namespace Ombi.Helpers
public string ImdbId { get; set; }
public bool Plex { get; set; }
public bool Any() => TheTvDb.HasValue() || TheMovieDb.HasValue() || ImdbId.HasValue();
public ProviderType Type
{
get

@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Ombi.Api.Emby;
using Ombi.Api.Jellyfin;
using Ombi.Api.Plex;
using Ombi.Api.TheMovieDb;
using Ombi.Api.TheMovieDb.Models;
using Ombi.Api.TvMaze;
@ -30,7 +31,8 @@ namespace Ombi.Schedule.Jobs.Ombi
IMovieDbApi movieApi,
ISettingsService<EmbySettings> embySettings, IEmbyApiFactory embyApi,
ISettingsService<JellyfinSettings> jellyfinSettings, IJellyfinApiFactory jellyfinApi,
IHubContext<NotificationHub> notification, IMediaCacheService mediaCacheService)
IHubContext<NotificationHub> notification, IMediaCacheService mediaCacheService,
IPlexApi plexApi)
{
_plexRepo = plexRepo;
_embyRepo = embyRepo;
@ -45,6 +47,7 @@ namespace Ombi.Schedule.Jobs.Ombi
_jellyfinApiFactory = jellyfinApi;
_notification = notification;
_mediaCacheService = mediaCacheService;
_plexApi = plexApi;
}
private readonly IPlexContentRepository _plexRepo;
@ -60,6 +63,7 @@ namespace Ombi.Schedule.Jobs.Ombi
private readonly IJellyfinApiFactory _jellyfinApiFactory;
private readonly IHubContext<NotificationHub> _notification;
private readonly IMediaCacheService _mediaCacheService;
private readonly IPlexApi _plexApi;
private IEmbyApi EmbyApi { get; set; }
private IJellyfinApi JellyfinApi { get; set; }
@ -75,7 +79,7 @@ namespace Ombi.Schedule.Jobs.Ombi
var settings = await _plexSettings.GetSettingsAsync();
if (settings.Enable)
{
await StartPlex();
await StartPlex(settings);
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex");
}
@ -112,12 +116,12 @@ namespace Ombi.Schedule.Jobs.Ombi
.SendAsync(NotificationHub.NotificationEvent, "Metadata Refresh Finished");
}
private async Task StartPlex()
private async Task StartPlex(PlexSettings settings)
{
// Ensure we check that we have not linked this item to a request
var allMovies = await _plexRepo.GetAll().Where(x =>
x.Type == MediaType.Movie && x.RequestId == null && (x.TheMovieDbId == null || x.ImdbId == null)).ToListAsync();
await StartPlexMovies(allMovies);
x.Type == MediaType.Movie && x.RequestId == null && ((x.TheMovieDbId == null || x.TheMovieDbId == string.Empty ) || (x.ImdbId == null || x.ImdbId == string.Empty))).ToListAsync();
await StartPlexMovies(allMovies, settings);
// Now Tv
var allTv = await _plexRepo.GetAll().Where(x =>
@ -245,7 +249,7 @@ namespace Ombi.Schedule.Jobs.Ombi
}
}
private async Task StartPlexMovies(List<PlexServerContent> allMovies)
private async Task StartPlexMovies(List<PlexServerContent> allMovies, PlexSettings settings)
{
foreach (var movie in allMovies)
{
@ -261,14 +265,58 @@ namespace Ombi.Schedule.Jobs.Ombi
if (!hasImdb)
{
var imdbId = await GetImdbId(hasTheMovieDb, false, movie.Title, movie.TheMovieDbId, string.Empty, RequestType.Movie);
movie.ImdbId = imdbId;
_plexRepo.UpdateWithoutSave(movie);
if (imdbId.HasValue())
{
movie.ImdbId = imdbId;
hasImdb = true;
_plexRepo.UpdateWithoutSave(movie);
}
}
if (!hasTheMovieDb)
{
var id = await GetTheMovieDbId(false, hasImdb, string.Empty, movie.ImdbId, movie.Title, true);
movie.TheMovieDbId = id;
_plexRepo.UpdateWithoutSave(movie);
if (id.HasValue())
{
movie.TheMovieDbId = id;
hasTheMovieDb = true;
_plexRepo.UpdateWithoutSave(movie);
}
}
if (!hasTheMovieDb || !hasImdb)
{
// Check to see if the Plex item has anything
if (!settings.Servers.Any())
{
continue;
}
var servers = settings.Servers[0];
var metaData = await _plexApi.GetMetadata(servers.PlexAuthToken, settings.Servers[0].FullUri, movie.Key);
var guids = new List<string>();
var meta = metaData.MediaContainer.Metadata.FirstOrDefault();
guids.Add(meta.guid);
if (meta.Guid != null)
{
foreach (var g in meta.Guid)
{
guids.Add(g.Id);
}
}
var providerIds = PlexHelper.GetProviderIdsFromMetadata(guids.ToArray());
if (providerIds.Any())
{
if (providerIds.TheMovieDb.HasValue() && !hasTheMovieDb)
{
movie.TheMovieDbId = providerIds.TheMovieDb;
_plexRepo.UpdateWithoutSave(movie);
}
if (providerIds.ImdbId.HasValue() && !hasImdb)
{
movie.ImdbId = providerIds.ImdbId;
_plexRepo.UpdateWithoutSave(movie);
}
}
}
await _plexRepo.SaveChangesAsync();

@ -379,6 +379,12 @@ namespace Ombi.Schedule.Jobs.Plex
}
var providerIds = PlexHelper.GetProviderIdsFromMetadata(guids.ToArray());
if (!providerIds.Any())
{
Logger.LogWarning($"Movie {movie.title} has no External Ids in Plex (ImdbId, TheMovieDbId). Skipping.");
continue;
}
var qualities = movie.Media?.Select(x => x.videoResolution);
var is4k = qualities != null && qualities.Any(x => x.Equals("4k", StringComparison.InvariantCultureIgnoreCase));
var selectedQuality = is4k ? null : qualities?.OrderBy(x => x)?.FirstOrDefault() ?? string.Empty;

Loading…
Cancel
Save