mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-31 12:00:06 -07:00
fix(metadata): improved the metadata job to also lookup the media in Plex to see if it has any more uptodate metadata
This commit is contained in:
parent
9cdd6f41cd
commit
83d1a15cc9
3 changed files with 66 additions and 10 deletions
|
@ -180,6 +180,8 @@ namespace Ombi.Helpers
|
||||||
public string ImdbId { get; set; }
|
public string ImdbId { get; set; }
|
||||||
public bool Plex { get; set; }
|
public bool Plex { get; set; }
|
||||||
|
|
||||||
|
public bool Any() => TheTvDb.HasValue() || TheMovieDb.HasValue() || ImdbId.HasValue();
|
||||||
|
|
||||||
public ProviderType Type
|
public ProviderType Type
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Ombi.Api.Emby;
|
using Ombi.Api.Emby;
|
||||||
using Ombi.Api.Jellyfin;
|
using Ombi.Api.Jellyfin;
|
||||||
|
using Ombi.Api.Plex;
|
||||||
using Ombi.Api.TheMovieDb;
|
using Ombi.Api.TheMovieDb;
|
||||||
using Ombi.Api.TheMovieDb.Models;
|
using Ombi.Api.TheMovieDb.Models;
|
||||||
using Ombi.Api.TvMaze;
|
using Ombi.Api.TvMaze;
|
||||||
|
@ -30,7 +31,8 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
IMovieDbApi movieApi,
|
IMovieDbApi movieApi,
|
||||||
ISettingsService<EmbySettings> embySettings, IEmbyApiFactory embyApi,
|
ISettingsService<EmbySettings> embySettings, IEmbyApiFactory embyApi,
|
||||||
ISettingsService<JellyfinSettings> jellyfinSettings, IJellyfinApiFactory jellyfinApi,
|
ISettingsService<JellyfinSettings> jellyfinSettings, IJellyfinApiFactory jellyfinApi,
|
||||||
IHubContext<NotificationHub> notification, IMediaCacheService mediaCacheService)
|
IHubContext<NotificationHub> notification, IMediaCacheService mediaCacheService,
|
||||||
|
IPlexApi plexApi)
|
||||||
{
|
{
|
||||||
_plexRepo = plexRepo;
|
_plexRepo = plexRepo;
|
||||||
_embyRepo = embyRepo;
|
_embyRepo = embyRepo;
|
||||||
|
@ -45,6 +47,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
_jellyfinApiFactory = jellyfinApi;
|
_jellyfinApiFactory = jellyfinApi;
|
||||||
_notification = notification;
|
_notification = notification;
|
||||||
_mediaCacheService = mediaCacheService;
|
_mediaCacheService = mediaCacheService;
|
||||||
|
_plexApi = plexApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IPlexContentRepository _plexRepo;
|
private readonly IPlexContentRepository _plexRepo;
|
||||||
|
@ -60,6 +63,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
private readonly IJellyfinApiFactory _jellyfinApiFactory;
|
private readonly IJellyfinApiFactory _jellyfinApiFactory;
|
||||||
private readonly IHubContext<NotificationHub> _notification;
|
private readonly IHubContext<NotificationHub> _notification;
|
||||||
private readonly IMediaCacheService _mediaCacheService;
|
private readonly IMediaCacheService _mediaCacheService;
|
||||||
|
private readonly IPlexApi _plexApi;
|
||||||
|
|
||||||
private IEmbyApi EmbyApi { get; set; }
|
private IEmbyApi EmbyApi { get; set; }
|
||||||
private IJellyfinApi JellyfinApi { get; set; }
|
private IJellyfinApi JellyfinApi { get; set; }
|
||||||
|
@ -75,7 +79,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
var settings = await _plexSettings.GetSettingsAsync();
|
var settings = await _plexSettings.GetSettingsAsync();
|
||||||
if (settings.Enable)
|
if (settings.Enable)
|
||||||
{
|
{
|
||||||
await StartPlex();
|
await StartPlex(settings);
|
||||||
|
|
||||||
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex");
|
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex");
|
||||||
}
|
}
|
||||||
|
@ -112,12 +116,12 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
.SendAsync(NotificationHub.NotificationEvent, "Metadata Refresh Finished");
|
.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
|
// Ensure we check that we have not linked this item to a request
|
||||||
var allMovies = await _plexRepo.GetAll().Where(x =>
|
var allMovies = await _plexRepo.GetAll().Where(x =>
|
||||||
x.Type == MediaType.Movie && x.RequestId == null && (x.TheMovieDbId == null || x.ImdbId == null)).ToListAsync();
|
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);
|
await StartPlexMovies(allMovies, settings);
|
||||||
|
|
||||||
// Now Tv
|
// Now Tv
|
||||||
var allTv = await _plexRepo.GetAll().Where(x =>
|
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)
|
foreach (var movie in allMovies)
|
||||||
{
|
{
|
||||||
|
@ -261,14 +265,58 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
if (!hasImdb)
|
if (!hasImdb)
|
||||||
{
|
{
|
||||||
var imdbId = await GetImdbId(hasTheMovieDb, false, movie.Title, movie.TheMovieDbId, string.Empty, RequestType.Movie);
|
var imdbId = await GetImdbId(hasTheMovieDb, false, movie.Title, movie.TheMovieDbId, string.Empty, RequestType.Movie);
|
||||||
movie.ImdbId = imdbId;
|
if (imdbId.HasValue())
|
||||||
_plexRepo.UpdateWithoutSave(movie);
|
{
|
||||||
|
movie.ImdbId = imdbId;
|
||||||
|
hasImdb = true;
|
||||||
|
_plexRepo.UpdateWithoutSave(movie);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!hasTheMovieDb)
|
if (!hasTheMovieDb)
|
||||||
{
|
{
|
||||||
var id = await GetTheMovieDbId(false, hasImdb, string.Empty, movie.ImdbId, movie.Title, true);
|
var id = await GetTheMovieDbId(false, hasImdb, string.Empty, movie.ImdbId, movie.Title, true);
|
||||||
movie.TheMovieDbId = id;
|
if (id.HasValue())
|
||||||
_plexRepo.UpdateWithoutSave(movie);
|
{
|
||||||
|
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();
|
await _plexRepo.SaveChangesAsync();
|
||||||
|
|
|
@ -379,6 +379,12 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
}
|
}
|
||||||
var providerIds = PlexHelper.GetProviderIdsFromMetadata(guids.ToArray());
|
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 qualities = movie.Media?.Select(x => x.videoResolution);
|
||||||
var is4k = qualities != null && qualities.Any(x => x.Equals("4k", StringComparison.InvariantCultureIgnoreCase));
|
var is4k = qualities != null && qualities.Any(x => x.Equals("4k", StringComparison.InvariantCultureIgnoreCase));
|
||||||
var selectedQuality = is4k ? null : qualities?.OrderBy(x => x)?.FirstOrDefault() ?? string.Empty;
|
var selectedQuality = is4k ? null : qualities?.OrderBy(x => x)?.FirstOrDefault() ?? string.Empty;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue