diff --git a/server/controllers/PodcastController.js b/server/controllers/PodcastController.js index a6801232..81029c95 100644 --- a/server/controllers/PodcastController.js +++ b/server/controllers/PodcastController.js @@ -219,7 +219,11 @@ class PodcastController { }) } - libraryItem.media.removeEpisode(episodeId) + // Remove episode from Podcast and library file + const episodeRemoved = libraryItem.media.removeEpisode(episodeId) + if (episodeRemoved && episodeRemoved.audioFile) { + libraryItem.removeLibraryFile(episodeRemoved.audioFile.ino) + } await this.db.updateLibraryItem(libraryItem) this.emitter('item_updated', libraryItem.toJSONExpanded()) diff --git a/server/objects/LibraryItem.js b/server/objects/LibraryItem.js index 05383f17..79743c8f 100644 --- a/server/objects/LibraryItem.js +++ b/server/objects/LibraryItem.js @@ -482,5 +482,16 @@ class LibraryItem { return success }) } + + removeLibraryFile(ino) { + if (!ino) return false + var libraryFile = this.libraryFiles.find(lf => lf.ino === ino) + if (libraryFile) { + this.libraryFiles = this.libraryFiles.filter(lf => lf.ino !== ino) + this.updatedAt = Date.now() + return true + } + return false + } } module.exports = LibraryItem \ No newline at end of file diff --git a/server/objects/mediaTypes/Podcast.js b/server/objects/mediaTypes/Podcast.js index a6e38c51..2a3fd0c6 100644 --- a/server/objects/mediaTypes/Podcast.js +++ b/server/objects/mediaTypes/Podcast.js @@ -240,7 +240,11 @@ class Podcast { } removeEpisode(episodeId) { - this.episodes = this.episodes.filter(ep => ep.id !== episodeId) + const episode = this.episodes.find(ep => ep.id === episodeId) + if (episode) { + this.episodes = this.episodes.filter(ep => ep.id !== episodeId) + } + return episode } getPlaybackTitle(episodeId) {