diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ffd83f80..10327a31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Fixed - Maintain stream continuity when playout is rebuilt for a channel that is actively being streamed +- Properly apply changes to episode title, sort title, outline and plot from Plex ## [0.6.2-beta] - 2022-06-18 ### Fixed diff --git a/ErsatzTV.Core.Tests/Fakes/FakeTelevisionRepository.cs b/ErsatzTV.Core.Tests/Fakes/FakeTelevisionRepository.cs index 1b8572970..259a111ef 100644 --- a/ErsatzTV.Core.Tests/Fakes/FakeTelevisionRepository.cs +++ b/ErsatzTV.Core.Tests/Fakes/FakeTelevisionRepository.cs @@ -1,7 +1,6 @@ using ErsatzTV.Core.Domain; using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.Core.Metadata; -using ErsatzTV.Core.Plex; namespace ErsatzTV.Core.Tests.Fakes; @@ -42,8 +41,7 @@ public class FakeTelevisionRepository : ITelevisionRepository public Task> GetShowByMetadata(int libraryPathId, ShowMetadata metadata) => throw new NotSupportedException(); - public Task>> - AddShow(int libraryPathId, string showFolder, ShowMetadata metadata) => + public Task>> AddShow(int libraryPathId, ShowMetadata metadata) => throw new NotSupportedException(); public Task> GetOrAddSeason(Show show, int libraryPathId, int seasonNumber) => @@ -74,36 +72,11 @@ public class FakeTelevisionRepository : ITelevisionRepository public Task AddDirector(EpisodeMetadata metadata, Director director) => throw new NotSupportedException(); public Task AddWriter(EpisodeMetadata metadata, Writer writer) => throw new NotSupportedException(); - public Task UpdatePath(int mediaFileId, string path) => throw new NotSupportedException(); - public Task>> GetOrAddPlexShow( - PlexLibrary library, - PlexShow item) => + public Task UpdateTitles(EpisodeMetadata metadata, string title, string sortTitle) => throw new NotSupportedException(); - public Task> GetOrAddPlexSeason(PlexLibrary library, PlexSeason item) => - throw new NotSupportedException(); - - public Task>> GetOrAddPlexEpisode( - PlexLibrary library, - PlexEpisode item) => - throw new NotSupportedException(); - - public Task> RemoveMissingPlexShows(PlexLibrary library, List showKeys) => - throw new NotSupportedException(); - - public Task RemoveMissingPlexSeasons(string showKey, List seasonKeys) => - throw new NotSupportedException(); + public Task UpdateOutline(EpisodeMetadata metadata, string outline) => throw new NotSupportedException(); - public Task> RemoveMissingPlexEpisodes(string seasonKey, List episodeKeys) => - throw new NotSupportedException(); - - public Task SetPlexEtag(PlexShow show, string etag) => throw new NotSupportedException(); - - public Task SetPlexEtag(PlexSeason season, string etag) => throw new NotSupportedException(); - - public Task SetPlexEtag(PlexEpisode episode, string etag) => throw new NotSupportedException(); - - public Task> GetExistingPlexEpisodes(PlexLibrary library, PlexSeason season) => - throw new NotSupportedException(); + public Task UpdatePlot(EpisodeMetadata metadata, string plot) => throw new NotSupportedException(); } diff --git a/ErsatzTV.Core/Interfaces/Repositories/ITelevisionRepository.cs b/ErsatzTV.Core/Interfaces/Repositories/ITelevisionRepository.cs index cccaceb76..ab297e061 100644 --- a/ErsatzTV.Core/Interfaces/Repositories/ITelevisionRepository.cs +++ b/ErsatzTV.Core/Interfaces/Repositories/ITelevisionRepository.cs @@ -22,12 +22,7 @@ public interface ITelevisionRepository Task GetEpisodeCount(int seasonId); Task> GetPagedEpisodes(int seasonId, int pageNumber, int pageSize); Task> GetShowByMetadata(int libraryPathId, ShowMetadata metadata); - - Task>> AddShow( - int libraryPathId, - string showFolder, - ShowMetadata metadata); - + Task>> AddShow(int libraryPathId, ShowMetadata metadata); Task> GetOrAddSeason(Show show, int libraryPathId, int seasonNumber); Task> GetOrAddEpisode(Season season, LibraryPath libraryPath, string path); Task> FindEpisodePaths(LibraryPath libraryPath); @@ -42,5 +37,7 @@ public interface ITelevisionRepository Task RemoveMetadata(Episode episode, EpisodeMetadata metadata); Task AddDirector(EpisodeMetadata metadata, Director director); Task AddWriter(EpisodeMetadata metadata, Writer writer); - Task UpdatePath(int mediaFileId, string path); + Task UpdateTitles(EpisodeMetadata metadata, string title, string sortTitle); + Task UpdateOutline(EpisodeMetadata metadata, string outline); + Task UpdatePlot(EpisodeMetadata metadata, string plot); } diff --git a/ErsatzTV.Core/Metadata/TelevisionFolderScanner.cs b/ErsatzTV.Core/Metadata/TelevisionFolderScanner.cs index 447c1f54d..fc41f2408 100644 --- a/ErsatzTV.Core/Metadata/TelevisionFolderScanner.cs +++ b/ErsatzTV.Core/Metadata/TelevisionFolderScanner.cs @@ -177,7 +177,7 @@ public class TelevisionFolderScanner : LocalFolderScanner, ITelevisionFolderScan return new MediaItemScanResult(show); } - return await _televisionRepository.AddShow(libraryPathId, showFolder, metadata); + return await _televisionRepository.AddShow(libraryPathId, metadata); } private async Task> ScanSeasons( diff --git a/ErsatzTV.Core/Plex/PlexTelevisionLibraryScanner.cs b/ErsatzTV.Core/Plex/PlexTelevisionLibraryScanner.cs index 5b8afbaca..cd68d4e7d 100644 --- a/ErsatzTV.Core/Plex/PlexTelevisionLibraryScanner.cs +++ b/ErsatzTV.Core/Plex/PlexTelevisionLibraryScanner.cs @@ -520,6 +520,34 @@ public class PlexTelevisionLibraryScanner : } } + if (fullMetadata.SortTitle != existingMetadata.SortTitle || fullMetadata.Title != existingMetadata.Title) + { + existingMetadata.Title = fullMetadata.Title; + existingMetadata.SortTitle = fullMetadata.SortTitle; + if (await _televisionRepository.UpdateTitles(existingMetadata, fullMetadata.Title, fullMetadata.SortTitle)) + { + result.IsUpdated = true; + } + } + + if (fullMetadata.Outline != existingMetadata.Outline) + { + existingMetadata.Outline = fullMetadata.Outline; + if (await _televisionRepository.UpdateOutline(existingMetadata, fullMetadata.Outline)) + { + result.IsUpdated = true; + } + } + + if (fullMetadata.Plot != existingMetadata.Plot) + { + existingMetadata.Plot = fullMetadata.Plot; + if (await _televisionRepository.UpdatePlot(existingMetadata, fullMetadata.Plot)) + { + result.IsUpdated = true; + } + } + if (await UpdateArtworkIfNeeded(existingMetadata, fullMetadata, ArtworkKind.Thumbnail)) { result.IsUpdated = true; diff --git a/ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs b/ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs index 45eb39aa4..233cdf23b 100644 --- a/ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs +++ b/ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs @@ -260,7 +260,6 @@ public class TelevisionRepository : ITelevisionRepository public async Task>> AddShow( int libraryPathId, - string showFolder, ShowMetadata metadata) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); @@ -464,12 +463,28 @@ public class TelevisionRepository : ITelevisionRepository new { writer.Name, MetadataId = metadata.Id }).Map(result => result > 0); } - public async Task UpdatePath(int mediaFileId, string path) + public async Task UpdateTitles(EpisodeMetadata metadata, string title, string sortTitle) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); return await dbContext.Connection.ExecuteAsync( - "UPDATE MediaFile SET Path = @Path WHERE Id = @MediaFileId", - new { Path = path, MediaFileId = mediaFileId }).Map(_ => Unit.Default); + "UPDATE EpisodeMetadata SET Title = @Title, SortTitle = @SortTitle WHERE Id = @MetadataId", + new { Title = title, SortTitle = sortTitle, MetadataId = metadata.Id }).Map(result => result > 0); + } + + public async Task UpdateOutline(EpisodeMetadata metadata, string outline) + { + await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); + return await dbContext.Connection.ExecuteAsync( + "UPDATE EpisodeMetadata SET Outline = @Outline WHERE Id = @MetadataId", + new { Outline = outline, MetadataId = metadata.Id }).Map(result => result > 0); + } + + public async Task UpdatePlot(EpisodeMetadata metadata, string plot) + { + await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); + return await dbContext.Connection.ExecuteAsync( + "UPDATE EpisodeMetadata SET Plot = @Plot WHERE Id = @MetadataId", + new { Plot = plot, MetadataId = metadata.Id }).Map(result => result > 0); } public async Task> GetShowItems(int showId) diff --git a/ErsatzTV/ErsatzTV.csproj b/ErsatzTV/ErsatzTV.csproj index 20906277a..b8248e883 100644 --- a/ErsatzTV/ErsatzTV.csproj +++ b/ErsatzTV/ErsatzTV.csproj @@ -55,8 +55,8 @@ - - + +