mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-14 01:16:52 +02:00
Update podcast episode downloads to have a fallback user agent string
This commit is contained in:
parent
b45085d2d6
commit
777a055fcd
@ -103,18 +103,39 @@ module.exports.resizeImage = resizeImage
|
|||||||
*/
|
*/
|
||||||
module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => {
|
module.exports.downloadPodcastEpisode = (podcastEpisodeDownload) => {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const response = await axios({
|
// Some podcasts fail due to user agent strings
|
||||||
url: podcastEpisodeDownload.url,
|
// See: https://github.com/advplyr/audiobookshelf/issues/3246 (requires iTMS user agent)
|
||||||
method: 'GET',
|
// See: https://github.com/advplyr/audiobookshelf/issues/4401 (requires no iTMS user agent)
|
||||||
responseType: 'stream',
|
const userAgents = ['audiobookshelf (+https://audiobookshelf.org; like iTMS)', 'audiobookshelf (+https://audiobookshelf.org)']
|
||||||
headers: {
|
|
||||||
'User-Agent': 'audiobookshelf (+https://audiobookshelf.org; like iTMS)'
|
let response = null
|
||||||
},
|
let lastError = null
|
||||||
timeout: global.PodcastDownloadTimeout
|
|
||||||
}).catch((error) => {
|
for (const userAgent of userAgents) {
|
||||||
Logger.error(`[ffmpegHelpers] Failed to download podcast episode with url "${podcastEpisodeDownload.url}"`, error)
|
try {
|
||||||
return null
|
response = await axios({
|
||||||
})
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user