From 1a67f57551775f3f19320595e6b04921077e9e2b Mon Sep 17 00:00:00 2001 From: advplyr Date: Tue, 14 Jan 2025 15:48:06 -0600 Subject: [PATCH] Update podcast downloads to fallback to download without tagging due to inaccurate rss feed enclosures #3837 --- server/managers/PodcastManager.js | 18 ++++++++++++++++-- server/utils/ffmpegHelpers.js | 17 +++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/server/managers/PodcastManager.js b/server/managers/PodcastManager.js index 0b45dfc4..64d001a3 100644 --- a/server/managers/PodcastManager.js +++ b/server/managers/PodcastManager.js @@ -115,10 +115,24 @@ class PodcastManager { let success = false if (this.currentDownload.isMp3) { // Download episode and tag it - success = await ffmpegHelpers.downloadPodcastEpisode(this.currentDownload).catch((error) => { + const ffmpegDownloadResponse = await ffmpegHelpers.downloadPodcastEpisode(this.currentDownload).catch((error) => { Logger.error(`[PodcastManager] Podcast Episode download failed`, error) - return false }) + success = !!ffmpegDownloadResponse?.success + + // If failed due to ffmpeg error, retry without tagging + // e.g. RSS feed may have incorrect file extension and file type + // See https://github.com/advplyr/audiobookshelf/issues/3837 + if (!success && ffmpegDownloadResponse?.isFfmpegError) { + Logger.info(`[PodcastManager] Retrying episode download without tagging`) + // Download episode only + success = await downloadFile(this.currentDownload.url, this.currentDownload.targetPath) + .then(() => true) + .catch((error) => { + Logger.error(`[PodcastManager] Podcast Episode download failed`, error) + return false + }) + } } else { // Download episode only success = await downloadFile(this.currentDownload.url, this.currentDownload.targetPath) diff --git a/server/utils/ffmpegHelpers.js b/server/utils/ffmpegHelpers.js index a365ca9e..9c88ef71 100644 --- a/server/utils/ffmpegHelpers.js +++ b/server/utils/ffmpegHelpers.js @@ -99,7 +99,7 @@ module.exports.resizeImage = resizeImage /** * * @param {import('../objects/PodcastEpisodeDownload')} podcastEpisodeDownload - * @returns + * @returns {Promise<{success: boolean, isFfmpegError?: boolean}>} */ module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => { return new Promise(async (resolve) => { @@ -115,7 +115,11 @@ module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => { Logger.error(`[ffmpegHelpers] Failed to download podcast episode with url "${podcastEpisodeDownload.url}"`, error) return null }) - if (!response) return resolve(false) + if (!response) { + return resolve({ + success: false + }) + } /** @type {import('../libs/fluentFfmpeg/index').FfmpegCommand} */ const ffmpeg = Ffmpeg(response.data) @@ -177,7 +181,10 @@ module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => { if (stderrLines.length) { Logger.error(`Full stderr dump for episode url "${podcastEpisodeDownload.url}": ${stderrLines.join('\n')}`) } - resolve(false) + resolve({ + success: false, + isFfmpegError: true + }) }) ffmpeg.on('progress', (progress) => { let progressPercent = 0 @@ -189,7 +196,9 @@ module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => { }) ffmpeg.on('end', () => { Logger.debug(`[FfmpegHelpers] downloadPodcastEpisode: Complete`) - resolve(podcastEpisodeDownload.targetPath) + resolve({ + success: true + }) }) ffmpeg.run() })