diff --git a/server/managers/PodcastManager.js b/server/managers/PodcastManager.js index 46f61902..f234e958 100644 --- a/server/managers/PodcastManager.js +++ b/server/managers/PodcastManager.js @@ -84,6 +84,13 @@ class PodcastManager { SocketAuthority.emitter('episode_download_started', podcastEpisodeDownload.toJSONForClient()) this.currentDownload = podcastEpisodeDownload + // If this file already exists then append the episode id to the filename + // e.g. "/tagesschau 20 Uhr.mp3" becomes "/tagesschau 20 Uhr (ep_asdfasdf).mp3" + // this handles podcasts where every title is the same (ref https://github.com/advplyr/audiobookshelf/issues/1802) + if (await fs.pathExists(this.currentDownload.targetPath)) { + this.currentDownload.appendEpisodeId = true + } + // Ignores all added files to this dir this.watcher.addIgnoreDir(this.currentDownload.libraryItem.path) diff --git a/server/objects/PodcastEpisodeDownload.js b/server/objects/PodcastEpisodeDownload.js index 601b7e60..6c4b343e 100644 --- a/server/objects/PodcastEpisodeDownload.js +++ b/server/objects/PodcastEpisodeDownload.js @@ -15,6 +15,8 @@ class PodcastEpisodeDownload { this.isFinished = false this.failed = false + this.appendEpisodeId = false + this.startedAt = null this.createdAt = null this.finishedAt = null @@ -29,6 +31,7 @@ class PodcastEpisodeDownload { libraryId: this.libraryId || null, isFinished: this.isFinished, failed: this.failed, + appendEpisodeId: this.appendEpisodeId, startedAt: this.startedAt, createdAt: this.createdAt, finishedAt: this.finishedAt, @@ -52,7 +55,9 @@ class PodcastEpisodeDownload { } get targetFilename() { - return sanitizeFilename(`${this.podcastEpisode.title}.${this.fileExtension}`) + const appendage = this.appendEpisodeId ? ` (${this.podcastEpisode.id})` : '' + const filename = `${this.podcastEpisode.title}${appendage}.${this.fileExtension}` + return sanitizeFilename(filename) } get targetPath() { return Path.join(this.libraryItem.path, this.targetFilename) diff --git a/server/objects/entities/PodcastEpisode.js b/server/objects/entities/PodcastEpisode.js index 394a0bea..a9f39fbf 100644 --- a/server/objects/entities/PodcastEpisode.js +++ b/server/objects/entities/PodcastEpisode.js @@ -109,7 +109,7 @@ class PodcastEpisode { } get size() { return this.audioFile.metadata.size } get enclosureUrl() { - return this.enclosure ? this.enclosure.url : null + return this.enclosure?.url || null } get pubYear() { if (!this.publishedAt) return null