From 7a87fb1c2eb20f415db7899f31a8f5f8deacbf0e Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Fri, 4 Nov 2022 06:25:51 -0500 Subject: [PATCH] fix removing emby and jellyfin libraries (#1011) * fix removing jellyfin and emby libraries * remove unneeded change --- CHANGELOG.md | 3 +++ .../Repositories/MediaSourceRepository.cs | 26 ++++++++++++++----- ErsatzTV.sln | 4 +-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a397b81f..0f5d0edf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Fix removing Jellyfin and Emby libraries that have been deleted from the source media server + ### Added - Add audio stream selector scripts for episodes and movies - This will let you customize which audio stream is selected for playback diff --git a/ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs b/ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs index 1c359ce6b..fe4ef6bc7 100644 --- a/ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs +++ b/ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs @@ -178,9 +178,16 @@ public class MediaSourceRepository : IMediaSourceRepository dbContext.JellyfinLibraries.Add(add); } - dbContext.JellyfinLibraries.RemoveRange(toDelete); + var libraryIds = toDelete.Map(l => l.Id).ToList(); + List deletedMediaIds = await dbContext.MediaItems + .Filter(mi => libraryIds.Contains(mi.LibraryPath.LibraryId)) + .Map(mi => mi.Id) + .ToListAsync(); - List ids = await DisableJellyfinLibrarySync(toDelete.Map(l => l.Id).ToList()); + foreach (JellyfinLibrary delete in toDelete) + { + dbContext.JellyfinLibraries.Remove(delete); + } foreach (JellyfinLibrary incoming in toUpdate) { @@ -214,7 +221,7 @@ public class MediaSourceRepository : IMediaSourceRepository await dbContext.SaveChangesAsync(); - return ids; + return deletedMediaIds; } public async Task> UpdateLibraries( @@ -231,9 +238,16 @@ public class MediaSourceRepository : IMediaSourceRepository dbContext.EmbyLibraries.Add(add); } - dbContext.EmbyLibraries.RemoveRange(toDelete); + var libraryIds = toDelete.Map(l => l.Id).ToList(); + List deletedMediaIds = await dbContext.MediaItems + .Filter(mi => libraryIds.Contains(mi.LibraryPath.LibraryId)) + .Map(mi => mi.Id) + .ToListAsync(); - List ids = await DisableEmbyLibrarySync(toDelete.Map(l => l.Id).ToList()); + foreach (EmbyLibrary delete in toDelete) + { + dbContext.EmbyLibraries.Remove(delete); + } foreach (EmbyLibrary incoming in toUpdate) { @@ -267,7 +281,7 @@ public class MediaSourceRepository : IMediaSourceRepository await dbContext.SaveChangesAsync(); - return ids; + return deletedMediaIds; } public async Task UpdatePathReplacements( diff --git a/ErsatzTV.sln b/ErsatzTV.sln index 11c53b1cc..f3e763054 100644 --- a/ErsatzTV.sln +++ b/ErsatzTV.sln @@ -27,8 +27,8 @@ Global {E83551AD-27E4-46E5-AD06-5B0DF797B8FF}.Release|Any CPU.Build.0 = Release|Any CPU {E83551AD-27E4-46E5-AD06-5B0DF797B8FF}.Debug No Sync|Any CPU.ActiveCfg = Debug No Sync|Any CPU {E83551AD-27E4-46E5-AD06-5B0DF797B8FF}.Debug No Sync|Any CPU.Build.0 = Debug No Sync|Any CPU - {E83551AD-27E4-46E5-AD06-5B0DF797B8FF}.Debug|Any CPU.ActiveCfg = Debug No Sync|Any CPU - {E83551AD-27E4-46E5-AD06-5B0DF797B8FF}.Debug|Any CPU.Build.0 = Debug No Sync|Any CPU + {E83551AD-27E4-46E5-AD06-5B0DF797B8FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E83551AD-27E4-46E5-AD06-5B0DF797B8FF}.Debug|Any CPU.Build.0 = Debug|Any CPU {C56FC23D-B863-401E-8E7C-E92BC307AFC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C56FC23D-B863-401E-8E7C-E92BC307AFC1}.Debug|Any CPU.Build.0 = Debug|Any CPU {C56FC23D-B863-401E-8E7C-E92BC307AFC1}.Release|Any CPU.ActiveCfg = Release|Any CPU