mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
Merge pull request #4626 from sephrat/media-update
Detect reidentified content in Emby and Jellyfin
This commit is contained in:
commit
0e8c47a1d3
7 changed files with 105 additions and 29 deletions
|
@ -157,9 +157,20 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
}
|
}
|
||||||
|
|
||||||
var existingTv = await _repo.GetByEmbyId(tvShow.Id);
|
var existingTv = await _repo.GetByEmbyId(tvShow.Id);
|
||||||
|
|
||||||
|
if (existingTv != null &&
|
||||||
|
( existingTv.ImdbId != tvShow.ProviderIds?.Imdb
|
||||||
|
|| existingTv.TheMovieDbId != tvShow.ProviderIds?.Tmdb
|
||||||
|
|| existingTv.TvDbId != tvShow.ProviderIds?.Tvdb))
|
||||||
|
{
|
||||||
|
_logger.LogDebug($"Series '{tvShow.Name}' has different IDs, probably a reidentification.");
|
||||||
|
await _repo.DeleteTv(existingTv);
|
||||||
|
existingTv = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (existingTv == null)
|
if (existingTv == null)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Adding new TV Show {0}", tvShow.Name);
|
_logger.LogDebug("Adding TV Show {0}", tvShow.Name);
|
||||||
mediaToAdd.Add(new EmbyContent
|
mediaToAdd.Add(new EmbyContent
|
||||||
{
|
{
|
||||||
TvDbId = tvShow.ProviderIds?.Tvdb,
|
TvDbId = tvShow.ProviderIds?.Tvdb,
|
||||||
|
@ -265,23 +276,21 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogDebug($"Adding new movie {movieInfo.Name}");
|
_logger.LogDebug($"Adding new movie {movieInfo.Name}");
|
||||||
|
var newMovie = new EmbyContent();
|
||||||
content.Add(new EmbyContent
|
newMovie.AddedAt = DateTime.UtcNow;
|
||||||
{
|
MapEmbyContent(newMovie, movieInfo, server, has4K, quality);
|
||||||
ImdbId = movieInfo.ProviderIds.Imdb,
|
content.Add(newMovie);
|
||||||
TheMovieDbId = movieInfo.ProviderIds?.Tmdb,
|
|
||||||
Title = movieInfo.Name,
|
|
||||||
Type = MediaType.Movie,
|
|
||||||
EmbyId = movieInfo.Id,
|
|
||||||
Url = EmbyHelper.GetEmbyMediaUrl(movieInfo.Id, server?.ServerId, server.ServerHostname),
|
|
||||||
AddedAt = DateTime.UtcNow,
|
|
||||||
Quality = has4K ? null : quality,
|
|
||||||
Has4K = has4K
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!quality.Equals(existingMovie?.Quality, StringComparison.InvariantCultureIgnoreCase))
|
var movieHasChanged = false;
|
||||||
|
if (existingMovie.ImdbId != movieInfo.ProviderIds.Imdb || existingMovie.TheMovieDbId != movieInfo.ProviderIds.Tmdb)
|
||||||
|
{
|
||||||
|
_logger.LogDebug($"Updating existing movie '{movieInfo.Name}'");
|
||||||
|
MapEmbyContent(existingMovie, movieInfo, server, has4K, quality);
|
||||||
|
movieHasChanged = true;
|
||||||
|
}
|
||||||
|
else if (!quality.Equals(existingMovie?.Quality, StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
_logger.LogDebug($"We have found another quality for Movie '{movieInfo.Name}', Quality: '{quality}'");
|
_logger.LogDebug($"We have found another quality for Movie '{movieInfo.Name}', Quality: '{quality}'");
|
||||||
existingMovie.Quality = has4K ? null : quality;
|
existingMovie.Quality = has4K ? null : quality;
|
||||||
|
@ -290,6 +299,11 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
// Probably could refactor here
|
// Probably could refactor here
|
||||||
// If a 4k movie comes in (we don't store the quality on 4k)
|
// If a 4k movie comes in (we don't store the quality on 4k)
|
||||||
// it will always get updated even know it's not changed
|
// it will always get updated even know it's not changed
|
||||||
|
movieHasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (movieHasChanged)
|
||||||
|
{
|
||||||
toUpdate.Add(existingMovie);
|
toUpdate.Add(existingMovie);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -300,6 +314,17 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MapEmbyContent(EmbyContent content, EmbyMovie movieInfo, EmbyServers server, bool has4K, string quality){
|
||||||
|
content.ImdbId = movieInfo.ProviderIds.Imdb;
|
||||||
|
content.TheMovieDbId = movieInfo.ProviderIds?.Tmdb;
|
||||||
|
content.Title = movieInfo.Name;
|
||||||
|
content.Type = MediaType.Movie;
|
||||||
|
content.EmbyId = movieInfo.Id;
|
||||||
|
content.Url = EmbyHelper.GetEmbyMediaUrl(movieInfo.Id, server?.ServerId, server.ServerHostname);
|
||||||
|
content.Quality = has4K ? null : quality;
|
||||||
|
content.Has4K = has4K;
|
||||||
|
}
|
||||||
|
|
||||||
private bool ValidateSettings(EmbyServers server)
|
private bool ValidateSettings(EmbyServers server)
|
||||||
{
|
{
|
||||||
if (server?.Ip == null || string.IsNullOrEmpty(server?.ApiKey))
|
if (server?.Ip == null || string.IsNullOrEmpty(server?.ApiKey))
|
||||||
|
|
|
@ -132,9 +132,20 @@ namespace Ombi.Schedule.Jobs.Jellyfin
|
||||||
}
|
}
|
||||||
|
|
||||||
var existingTv = await _repo.GetByJellyfinId(tvShow.Id);
|
var existingTv = await _repo.GetByJellyfinId(tvShow.Id);
|
||||||
|
|
||||||
|
if (existingTv != null &&
|
||||||
|
( existingTv.ImdbId != tvShow.ProviderIds?.Imdb
|
||||||
|
|| existingTv.TheMovieDbId != tvShow.ProviderIds?.Tmdb
|
||||||
|
|| existingTv.TvDbId != tvShow.ProviderIds?.Tvdb))
|
||||||
|
{
|
||||||
|
_logger.LogDebug($"Series '{tvShow.Name}' has different IDs, probably a reidentification.");
|
||||||
|
await _repo.DeleteTv(existingTv);
|
||||||
|
existingTv = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (existingTv == null)
|
if (existingTv == null)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Adding new TV Show {0}", tvShow.Name);
|
_logger.LogDebug("Adding TV Show {0}", tvShow.Name);
|
||||||
mediaToAdd.Add(new JellyfinContent
|
mediaToAdd.Add(new JellyfinContent
|
||||||
{
|
{
|
||||||
TvDbId = tvShow.ProviderIds?.Tvdb,
|
TvDbId = tvShow.ProviderIds?.Tvdb,
|
||||||
|
@ -230,22 +241,21 @@ namespace Ombi.Schedule.Jobs.Jellyfin
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogDebug($"Adding new movie {movieInfo.Name}");
|
_logger.LogDebug($"Adding new movie {movieInfo.Name}");
|
||||||
content.Add(new JellyfinContent
|
var newMovie = new JellyfinContent();
|
||||||
{
|
newMovie.AddedAt = DateTime.UtcNow;
|
||||||
ImdbId = movieInfo.ProviderIds.Imdb,
|
MapJellyfinMovie(newMovie, movieInfo, server, has4K, quality);
|
||||||
TheMovieDbId = movieInfo.ProviderIds?.Tmdb,
|
content.Add(newMovie);;
|
||||||
Title = movieInfo.Name,
|
|
||||||
Type = MediaType.Movie,
|
|
||||||
JellyfinId = movieInfo.Id,
|
|
||||||
Url = JellyfinHelper.GetJellyfinMediaUrl(movieInfo.Id, server?.ServerId, server.ServerHostname),
|
|
||||||
AddedAt = DateTime.UtcNow,
|
|
||||||
Quality = has4K ? null : quality,
|
|
||||||
Has4K = has4K
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!quality.Equals(existingMovie?.Quality, StringComparison.InvariantCultureIgnoreCase))
|
var movieHasChanged = false;
|
||||||
|
if (existingMovie.ImdbId != movieInfo.ProviderIds.Imdb || existingMovie.TheMovieDbId != movieInfo.ProviderIds.Tmdb)
|
||||||
|
{
|
||||||
|
_logger.LogDebug($"Updating existing movie '{movieInfo.Name}'");
|
||||||
|
MapJellyfinMovie(existingMovie, movieInfo, server, has4K, quality);
|
||||||
|
movieHasChanged = true;
|
||||||
|
}
|
||||||
|
else if (!quality.Equals(existingMovie?.Quality, StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
_logger.LogDebug($"We have found another quality for Movie '{movieInfo.Name}', Quality: '{quality}'");
|
_logger.LogDebug($"We have found another quality for Movie '{movieInfo.Name}', Quality: '{quality}'");
|
||||||
existingMovie.Quality = has4K ? null : quality;
|
existingMovie.Quality = has4K ? null : quality;
|
||||||
|
@ -255,6 +265,12 @@ namespace Ombi.Schedule.Jobs.Jellyfin
|
||||||
// If a 4k movie comes in (we don't store the quality on 4k)
|
// If a 4k movie comes in (we don't store the quality on 4k)
|
||||||
// it will always get updated even know it's not changed
|
// it will always get updated even know it's not changed
|
||||||
toUpdate.Add(existingMovie);
|
toUpdate.Add(existingMovie);
|
||||||
|
movieHasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (movieHasChanged)
|
||||||
|
{
|
||||||
|
toUpdate.Add(existingMovie);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -264,6 +280,18 @@ namespace Ombi.Schedule.Jobs.Jellyfin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MapJellyfinMovie(JellyfinContent content, JellyfinMovie movieInfo, JellyfinServers server, bool has4K, string quality)
|
||||||
|
{
|
||||||
|
content.ImdbId = movieInfo.ProviderIds.Imdb;
|
||||||
|
content.TheMovieDbId = movieInfo.ProviderIds?.Tmdb;
|
||||||
|
content.Title = movieInfo.Name;
|
||||||
|
content.Type = MediaType.Movie;
|
||||||
|
content.JellyfinId = movieInfo.Id;
|
||||||
|
content.Url = JellyfinHelper.GetJellyfinMediaUrl(movieInfo.Id, server?.ServerId, server.ServerHostname);
|
||||||
|
content.Quality = has4K ? null : quality;
|
||||||
|
content.Has4K = has4K;
|
||||||
|
}
|
||||||
|
|
||||||
private bool ValidateSettings(JellyfinServers server)
|
private bool ValidateSettings(JellyfinServers server)
|
||||||
{
|
{
|
||||||
if (server?.Ip == null || string.IsNullOrEmpty(server?.ApiKey))
|
if (server?.Ip == null || string.IsNullOrEmpty(server?.ApiKey))
|
||||||
|
|
|
@ -102,6 +102,13 @@ namespace Ombi.Store.Repository
|
||||||
return InternalSaveChanges();
|
return InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task DeleteTv(EmbyContent tv)
|
||||||
|
{
|
||||||
|
var episodesToDelete = GetAllEpisodes().Cast<EmbyEpisode>().Where(x => x.ParentId == tv.EmbyId).ToList();
|
||||||
|
Db.EmbyEpisode.RemoveRange(episodesToDelete);
|
||||||
|
await Delete(tv);
|
||||||
|
}
|
||||||
|
|
||||||
public override RecentlyAddedType RecentlyAddedType => RecentlyAddedType.Emby;
|
public override RecentlyAddedType RecentlyAddedType => RecentlyAddedType.Emby;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,6 +14,7 @@ namespace Ombi.Store.Repository
|
||||||
IQueryable<IMediaServerEpisode> GetAllEpisodes();
|
IQueryable<IMediaServerEpisode> GetAllEpisodes();
|
||||||
Task<IMediaServerEpisode> Add(IMediaServerEpisode content);
|
Task<IMediaServerEpisode> Add(IMediaServerEpisode content);
|
||||||
Task AddRange(IEnumerable<IMediaServerEpisode> content);
|
Task AddRange(IEnumerable<IMediaServerEpisode> content);
|
||||||
|
Task DeleteTv(Content tv);
|
||||||
void UpdateWithoutSave(IMediaServerContent existingContent);
|
void UpdateWithoutSave(IMediaServerContent existingContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -104,6 +104,13 @@ namespace Ombi.Store.Repository
|
||||||
return InternalSaveChanges();
|
return InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task DeleteTv(JellyfinContent tv)
|
||||||
|
{
|
||||||
|
var episodesToDelete = GetAllEpisodes().Cast<JellyfinEpisode>().Where(x => x.ParentId == tv.JellyfinId).ToList();
|
||||||
|
Db.JellyfinEpisode.RemoveRange(episodesToDelete);
|
||||||
|
await Delete(tv);
|
||||||
|
}
|
||||||
|
|
||||||
public override RecentlyAddedType RecentlyAddedType => RecentlyAddedType.Jellyfin;
|
public override RecentlyAddedType RecentlyAddedType => RecentlyAddedType.Jellyfin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,6 @@ namespace Ombi.Store.Repository
|
||||||
public abstract Task AddRange(IEnumerable<IMediaServerEpisode> content);
|
public abstract Task AddRange(IEnumerable<IMediaServerEpisode> content);
|
||||||
public abstract void UpdateWithoutSave(IMediaServerContent existingContent);
|
public abstract void UpdateWithoutSave(IMediaServerContent existingContent);
|
||||||
public abstract Task UpdateRange(IEnumerable<IMediaServerContent> existingContent);
|
public abstract Task UpdateRange(IEnumerable<IMediaServerContent> existingContent);
|
||||||
|
public abstract Task DeleteTv(T tv);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -169,5 +169,12 @@ namespace Ombi.Store.Repository
|
||||||
Db.PlexServerContent.UpdateRange((IEnumerable<PlexServerContent>)existingContent);
|
Db.PlexServerContent.UpdateRange((IEnumerable<PlexServerContent>)existingContent);
|
||||||
return InternalSaveChanges();
|
return InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Task DeleteTv(PlexServerContent tv)
|
||||||
|
{
|
||||||
|
// not used for now
|
||||||
|
// TODO: delete episodes, then delete series
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue