From 62194b8781a98acfd4af24348fbc5702af1495d9 Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 10 Apr 2025 17:39:41 -0500 Subject: [PATCH 1/2] Fix podcast re-scan promise --- server/scanner/PodcastScanner.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/server/scanner/PodcastScanner.js b/server/scanner/PodcastScanner.js index 4170136d..7ecf3b08 100644 --- a/server/scanner/PodcastScanner.js +++ b/server/scanner/PodcastScanner.js @@ -59,17 +59,17 @@ class PodcastScanner { if (libraryItemData.hasAudioFileChanges || libraryItemData.audioLibraryFiles.length !== existingPodcastEpisodes.length) { // Filter out and destroy episodes that were removed - existingPodcastEpisodes = await Promise.all( - existingPodcastEpisodes.filter(async (ep) => { - if (libraryItemData.checkAudioFileRemoved(ep.audioFile)) { - libraryScan.addLog(LogLevel.INFO, `Podcast episode "${ep.title}" audio file was removed`) - // TODO: Should clean up other data linked to this episode - await ep.destroy() - return false - } - return true - }) - ) + const episodesToRemove = [] + existingPodcastEpisodes = existingPodcastEpisodes.filter((ep) => { + if (libraryItemData.checkAudioFileRemoved(ep.audioFile)) { + libraryScan.addLog(LogLevel.INFO, `Podcast episode "${ep.title}" audio file was removed`) + episodesToRemove.push(ep) + return false + } + return true + }) + + await Promise.all(episodesToRemove.map((ep) => ep.destroy())) // Update audio files that were modified if (libraryItemData.audioLibraryFilesModified.length) { @@ -139,7 +139,6 @@ class PodcastScanner { } let hasMediaChanges = false - if (existingPodcastEpisodes.length !== media.numEpisodes) { media.numEpisodes = existingPodcastEpisodes.length hasMediaChanges = true From b47d7b734de2e1e182a56c10be55f8bd1c06bcd8 Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 10 Apr 2025 17:51:42 -0500 Subject: [PATCH 2/2] Update podcast scanner to remove media progress and episodes from playlist --- server/scanner/PodcastScanner.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/server/scanner/PodcastScanner.js b/server/scanner/PodcastScanner.js index 7ecf3b08..c9569c3a 100644 --- a/server/scanner/PodcastScanner.js +++ b/server/scanner/PodcastScanner.js @@ -62,14 +62,33 @@ class PodcastScanner { const episodesToRemove = [] existingPodcastEpisodes = existingPodcastEpisodes.filter((ep) => { if (libraryItemData.checkAudioFileRemoved(ep.audioFile)) { - libraryScan.addLog(LogLevel.INFO, `Podcast episode "${ep.title}" audio file was removed`) episodesToRemove.push(ep) return false } return true }) - await Promise.all(episodesToRemove.map((ep) => ep.destroy())) + if (episodesToRemove.length) { + // Remove episodes from playlists and media progress + const episodeIds = episodesToRemove.map((ep) => ep.id) + await Database.playlistModel.removeMediaItemsFromPlaylists(episodeIds) + const mediaProgressRemoved = await Database.mediaProgressModel.destroy({ + where: { + mediaItemId: episodeIds + } + }) + if (mediaProgressRemoved) { + libraryScan.addLog(LogLevel.INFO, `Removed ${mediaProgressRemoved} media progress for episodes`) + } + + // Remove episodes + await Promise.all( + episodesToRemove.map(async (ep) => { + await ep.destroy() + libraryScan.addLog(LogLevel.INFO, `Podcast episode "${ep.title}" audio file was removed`) + }) + ) + } // Update audio files that were modified if (libraryItemData.audioLibraryFilesModified.length) {