mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Update podcast RSS parser to handle HTML not wrapped in CDATA #3778
This commit is contained in:
parent
7001adb4dd
commit
0f20ed101e
@ -52,6 +52,29 @@ function extractFirstArrayItem(json, key) {
|
|||||||
return json[key][0]
|
return json[key][0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractStringOrStringify(json) {
|
||||||
|
try {
|
||||||
|
if (typeof json[Object.keys(json)[0]]?.[0] === 'string') {
|
||||||
|
return json[Object.keys(json)[0]][0]
|
||||||
|
}
|
||||||
|
// Handles case where html was included without being wrapped in CDATA
|
||||||
|
return JSON.stringify(value)
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractFirstArrayItemString(json, key) {
|
||||||
|
const item = extractFirstArrayItem(json, key)
|
||||||
|
if (!item) return ''
|
||||||
|
if (typeof item === 'object') {
|
||||||
|
if (item?.['_'] && typeof item['_'] === 'string') return item['_']
|
||||||
|
|
||||||
|
return extractStringOrStringify(item)
|
||||||
|
}
|
||||||
|
return typeof item === 'string' ? item : ''
|
||||||
|
}
|
||||||
|
|
||||||
function extractImage(channel) {
|
function extractImage(channel) {
|
||||||
if (!channel.image || !channel.image.url || !channel.image.url.length) {
|
if (!channel.image || !channel.image.url || !channel.image.url.length) {
|
||||||
if (!channel['itunes:image'] || !channel['itunes:image'].length || !channel['itunes:image'][0]['$']) {
|
if (!channel['itunes:image'] || !channel['itunes:image'].length || !channel['itunes:image'][0]['$']) {
|
||||||
@ -101,7 +124,7 @@ function extractPodcastMetadata(channel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (channel['description']) {
|
if (channel['description']) {
|
||||||
const rawDescription = extractFirstArrayItem(channel, 'description') || ''
|
const rawDescription = extractFirstArrayItemString(channel, 'description')
|
||||||
metadata.description = htmlSanitizer.sanitize(rawDescription.trim())
|
metadata.description = htmlSanitizer.sanitize(rawDescription.trim())
|
||||||
metadata.descriptionPlain = htmlSanitizer.stripAllTags(rawDescription.trim())
|
metadata.descriptionPlain = htmlSanitizer.stripAllTags(rawDescription.trim())
|
||||||
}
|
}
|
||||||
@ -145,7 +168,8 @@ function extractEpisodeData(item) {
|
|||||||
|
|
||||||
// Supposed to be the plaintext description but not always followed
|
// Supposed to be the plaintext description but not always followed
|
||||||
if (item['description']) {
|
if (item['description']) {
|
||||||
const rawDescription = extractFirstArrayItem(item, 'description') || ''
|
const rawDescription = extractFirstArrayItemString(item, 'description')
|
||||||
|
|
||||||
if (!episode.description) episode.description = htmlSanitizer.sanitize(rawDescription.trim())
|
if (!episode.description) episode.description = htmlSanitizer.sanitize(rawDescription.trim())
|
||||||
episode.descriptionPlain = htmlSanitizer.stripAllTags(rawDescription.trim())
|
episode.descriptionPlain = htmlSanitizer.stripAllTags(rawDescription.trim())
|
||||||
}
|
}
|
||||||
@ -175,9 +199,7 @@ function extractEpisodeData(item) {
|
|||||||
const arrayFields = ['title', 'itunes:episodeType', 'itunes:season', 'itunes:episode', 'itunes:author', 'itunes:duration', 'itunes:explicit', 'itunes:subtitle']
|
const arrayFields = ['title', 'itunes:episodeType', 'itunes:season', 'itunes:episode', 'itunes:author', 'itunes:duration', 'itunes:explicit', 'itunes:subtitle']
|
||||||
arrayFields.forEach((key) => {
|
arrayFields.forEach((key) => {
|
||||||
const cleanKey = key.split(':').pop()
|
const cleanKey = key.split(':').pop()
|
||||||
let value = extractFirstArrayItem(item, key)
|
episode[cleanKey] = extractFirstArrayItemString(item, key)
|
||||||
if (value?.['_']) value = value['_']
|
|
||||||
episode[cleanKey] = value
|
|
||||||
})
|
})
|
||||||
return episode
|
return episode
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user