Compare commits

..

No commits in common. "2cc58b2c8af8fb17ccbd708f34cd7ae824034445" and "22f6e86a12bd4a52f5cbddd76ea043cae3e3f3d0" have entirely different histories.

View file

@ -103,39 +103,18 @@ module.exports.resizeImage = resizeImage
*/ */
module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => { module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
// Some podcasts fail due to user agent strings const response = await axios({
// See: https://github.com/advplyr/audiobookshelf/issues/3246 (requires iTMS user agent) url: podcastEpisodeDownload.url,
// See: https://github.com/advplyr/audiobookshelf/issues/4401 (requires no iTMS user agent) method: 'GET',
const userAgents = ['audiobookshelf (+https://audiobookshelf.org; like iTMS)', 'audiobookshelf (+https://audiobookshelf.org)'] responseType: 'stream',
headers: {
let response = null 'User-Agent': 'audiobookshelf (+https://audiobookshelf.org)'
let lastError = null },
timeout: global.PodcastDownloadTimeout
for (const userAgent of userAgents) { }).catch((error) => {
try { Logger.error(`[ffmpegHelpers] Failed to download podcast episode with url "${podcastEpisodeDownload.url}"`, error)
response = await axios({ return null
url: podcastEpisodeDownload.url, })
method: 'GET',
responseType: 'stream',
headers: {
'User-Agent': userAgent
},
timeout: global.PodcastDownloadTimeout
})
Logger.debug(`[ffmpegHelpers] Successfully connected with User-Agent: ${userAgent}`)
break
} catch (error) {
lastError = error
Logger.warn(`[ffmpegHelpers] Failed to download podcast episode with User-Agent "${userAgent}" for url "${podcastEpisodeDownload.url}"`, error.message)
// If this is the last attempt, log the full error
if (userAgent === userAgents[userAgents.length - 1]) {
Logger.error(`[ffmpegHelpers] All User-Agent attempts failed for url "${podcastEpisodeDownload.url}"`, lastError)
}
}
}
if (!response) { if (!response) {
return resolve({ return resolve({
success: false success: false