mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 09:51:37 +00:00
Compare commits
No commits in common. "2cc58b2c8af8fb17ccbd708f34cd7ae824034445" and "22f6e86a12bd4a52f5cbddd76ea043cae3e3f3d0" have entirely different histories.
2cc58b2c8a
...
22f6e86a12
1 changed files with 12 additions and 33 deletions
|
|
@ -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)
|
|
||||||
// See: https://github.com/advplyr/audiobookshelf/issues/4401 (requires no iTMS user agent)
|
|
||||||
const userAgents = ['audiobookshelf (+https://audiobookshelf.org; like iTMS)', 'audiobookshelf (+https://audiobookshelf.org)']
|
|
||||||
|
|
||||||
let response = null
|
|
||||||
let lastError = null
|
|
||||||
|
|
||||||
for (const userAgent of userAgents) {
|
|
||||||
try {
|
|
||||||
response = await axios({
|
|
||||||
url: podcastEpisodeDownload.url,
|
url: podcastEpisodeDownload.url,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
responseType: 'stream',
|
responseType: 'stream',
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': userAgent
|
'User-Agent': 'audiobookshelf (+https://audiobookshelf.org)'
|
||||||
},
|
},
|
||||||
timeout: global.PodcastDownloadTimeout
|
timeout: global.PodcastDownloadTimeout
|
||||||
|
}).catch((error) => {
|
||||||
|
Logger.error(`[ffmpegHelpers] Failed to download podcast episode with url "${podcastEpisodeDownload.url}"`, error)
|
||||||
|
return null
|
||||||
})
|
})
|
||||||
|
|
||||||
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…
Add table
Add a link
Reference in a new issue