diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a9157bbd..342fad96c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Add downsampling to support transcoding 10-bit HEVC content with the h264_vaapi encoder +- Fix updating statistics when media items are replaced ## [0.0.62-alpha] - 2021-10-05 ### Added diff --git a/ErsatzTV.Core/Emby/EmbyMovieLibraryScanner.cs b/ErsatzTV.Core/Emby/EmbyMovieLibraryScanner.cs index 312fa139e..df33008eb 100644 --- a/ErsatzTV.Core/Emby/EmbyMovieLibraryScanner.cs +++ b/ErsatzTV.Core/Emby/EmbyMovieLibraryScanner.cs @@ -96,6 +96,8 @@ namespace ErsatzTV.Core.Emby foreach (EmbyMovie incoming in validMovies) { + EmbyMovie incomingMovie = incoming; + decimal percentCompletion = (decimal) validMovies.IndexOf(incoming) / validMovies.Count; await _mediator.Publish(new LibraryScanProgress(library.Id, percentCompletion)); @@ -122,12 +124,14 @@ namespace ErsatzTV.Core.Emby updateStatistics = true; incoming.LibraryPathId = library.Paths.Head().Id; - Option updated = await _movieRepository.UpdateEmby(incoming); - if (updated.IsSome) + Option maybeUpdated = await _movieRepository.UpdateEmby(incoming); + foreach (EmbyMovie updated in maybeUpdated) { await _searchIndex.UpdateItems( _searchRepository, - new List { updated.ValueUnsafe() }); + new List { updated }); + + incomingMovie = updated; } } catch (Exception ex) @@ -174,12 +178,12 @@ namespace ErsatzTV.Core.Emby _logger.LogDebug("Refreshing {Attribute} for {Path}", "Statistics", localPath); Either refreshResult = - await _localStatisticsProvider.RefreshStatistics(ffprobePath, incoming, localPath); + await _localStatisticsProvider.RefreshStatistics(ffprobePath, incomingMovie, localPath); await refreshResult.Match( async _ => { - Option updated = await _searchRepository.GetItemToIndex(incoming.Id); + Option updated = await _searchRepository.GetItemToIndex(incomingMovie.Id); if (updated.IsSome) { await _searchIndex.UpdateItems( diff --git a/ErsatzTV.Core/Emby/EmbyTelevisionLibraryScanner.cs b/ErsatzTV.Core/Emby/EmbyTelevisionLibraryScanner.cs index fd61e4f1f..1dddb5640 100644 --- a/ErsatzTV.Core/Emby/EmbyTelevisionLibraryScanner.cs +++ b/ErsatzTV.Core/Emby/EmbyTelevisionLibraryScanner.cs @@ -326,6 +326,7 @@ namespace ErsatzTV.Core.Emby { foreach (EmbyEpisode incoming in episodes) { + EmbyEpisode incomingEpisode = incoming; var updateStatistics = false; Option maybeExisting = existingEpisodes.Find(ie => ie.ItemId == incoming.ItemId); @@ -349,12 +350,14 @@ namespace ErsatzTV.Core.Emby incoming.SeasonId = season.Id; incoming.LibraryPathId = library.Paths.Head().Id; - Option updated = await _televisionRepository.Update(incoming); - if (updated.IsSome) + Option maybeUpdated = await _televisionRepository.Update(incoming); + foreach (EmbyEpisode updated in maybeUpdated) { await _searchIndex.UpdateItems( _searchRepository, - new List { updated.ValueUnsafe() }); + new List { updated }); + + incomingEpisode = updated; } } catch (Exception ex) @@ -403,7 +406,7 @@ namespace ErsatzTV.Core.Emby _logger.LogDebug("Refreshing {Attribute} for {Path}", "Statistics", localPath); Either refreshResult = - await _localStatisticsProvider.RefreshStatistics(ffprobePath, incoming, localPath); + await _localStatisticsProvider.RefreshStatistics(ffprobePath, incomingEpisode, localPath); refreshResult.Match( _ => { }, diff --git a/ErsatzTV.Core/Jellyfin/JellyfinMovieLibraryScanner.cs b/ErsatzTV.Core/Jellyfin/JellyfinMovieLibraryScanner.cs index f26cbec87..a90e2379a 100644 --- a/ErsatzTV.Core/Jellyfin/JellyfinMovieLibraryScanner.cs +++ b/ErsatzTV.Core/Jellyfin/JellyfinMovieLibraryScanner.cs @@ -96,6 +96,8 @@ namespace ErsatzTV.Core.Jellyfin foreach (JellyfinMovie incoming in validMovies) { + JellyfinMovie incomingMovie = incoming; + decimal percentCompletion = (decimal) validMovies.IndexOf(incoming) / validMovies.Count; await _mediator.Publish(new LibraryScanProgress(library.Id, percentCompletion)); @@ -122,12 +124,14 @@ namespace ErsatzTV.Core.Jellyfin updateStatistics = true; incoming.LibraryPathId = library.Paths.Head().Id; - Option updated = await _movieRepository.UpdateJellyfin(incoming); - if (updated.IsSome) + Option maybeUpdated = await _movieRepository.UpdateJellyfin(incoming); + foreach (JellyfinMovie updated in maybeUpdated) { await _searchIndex.UpdateItems( _searchRepository, - new List { updated.ValueUnsafe() }); + new List { updated }); + + incomingMovie = updated; } } catch (Exception ex) @@ -174,12 +178,12 @@ namespace ErsatzTV.Core.Jellyfin _logger.LogDebug("Refreshing {Attribute} for {Path}", "Statistics", localPath); Either refreshResult = - await _localStatisticsProvider.RefreshStatistics(ffprobePath, incoming, localPath); + await _localStatisticsProvider.RefreshStatistics(ffprobePath, incomingMovie, localPath); await refreshResult.Match( async _ => { - Option updated = await _searchRepository.GetItemToIndex(incoming.Id); + Option updated = await _searchRepository.GetItemToIndex(incomingMovie.Id); if (updated.IsSome) { await _searchIndex.UpdateItems( diff --git a/ErsatzTV.Core/Jellyfin/JellyfinTelevisionLibraryScanner.cs b/ErsatzTV.Core/Jellyfin/JellyfinTelevisionLibraryScanner.cs index 6bbecf8f2..ed93783c9 100644 --- a/ErsatzTV.Core/Jellyfin/JellyfinTelevisionLibraryScanner.cs +++ b/ErsatzTV.Core/Jellyfin/JellyfinTelevisionLibraryScanner.cs @@ -327,6 +327,8 @@ namespace ErsatzTV.Core.Jellyfin { foreach (JellyfinEpisode incoming in episodes) { + JellyfinEpisode incomingEpisode = incoming; + var updateStatistics = false; Option maybeExisting = existingEpisodes.Find(ie => ie.ItemId == incoming.ItemId); @@ -350,12 +352,14 @@ namespace ErsatzTV.Core.Jellyfin incoming.SeasonId = season.Id; incoming.LibraryPathId = library.Paths.Head().Id; - Option updated = await _televisionRepository.Update(incoming); - if (updated.IsSome) + Option maybeUpdated = await _televisionRepository.Update(incoming); + foreach (JellyfinEpisode updated in maybeUpdated) { await _searchIndex.UpdateItems( _searchRepository, - new List { updated.ValueUnsafe() }); + new List { updated }); + + incomingEpisode = updated; } } catch (Exception ex) @@ -404,7 +408,7 @@ namespace ErsatzTV.Core.Jellyfin _logger.LogDebug("Refreshing {Attribute} for {Path}", "Statistics", localPath); Either refreshResult = - await _localStatisticsProvider.RefreshStatistics(ffprobePath, incoming, localPath); + await _localStatisticsProvider.RefreshStatistics(ffprobePath, incomingEpisode, localPath); refreshResult.Match( _ => { }, diff --git a/ErsatzTV.Core/Plex/PlexMovieLibraryScanner.cs b/ErsatzTV.Core/Plex/PlexMovieLibraryScanner.cs index 6fe81ae1b..5f22045dc 100644 --- a/ErsatzTV.Core/Plex/PlexMovieLibraryScanner.cs +++ b/ErsatzTV.Core/Plex/PlexMovieLibraryScanner.cs @@ -183,7 +183,7 @@ namespace ErsatzTV.Core.Plex _logger.LogDebug("Refreshing {Attribute} for {Path}", "Statistics", localPath); Either refreshResult = - await _localStatisticsProvider.RefreshStatistics(ffprobePath, incoming, localPath); + await _localStatisticsProvider.RefreshStatistics(ffprobePath, existing, localPath); await refreshResult.Match( async _ => diff --git a/ErsatzTV.Core/Plex/PlexTelevisionLibraryScanner.cs b/ErsatzTV.Core/Plex/PlexTelevisionLibraryScanner.cs index f75f8e0a3..e27b0caed 100644 --- a/ErsatzTV.Core/Plex/PlexTelevisionLibraryScanner.cs +++ b/ErsatzTV.Core/Plex/PlexTelevisionLibraryScanner.cs @@ -542,7 +542,7 @@ namespace ErsatzTV.Core.Plex _logger.LogDebug("Refreshing {Attribute} for {Path}", "Statistics", localPath); Either refreshResult = - await _localStatisticsProvider.RefreshStatistics(ffprobePath, incoming, localPath); + await _localStatisticsProvider.RefreshStatistics(ffprobePath, existing, localPath); await refreshResult.Match( async _ =>