mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-01 00:18:14 +01:00
Update RSS feed to exclude empty tags, format duration, use CDATA
This commit is contained in:
parent
f13283b950
commit
54a4b09592
@ -561,7 +561,42 @@ class Feed extends Model {
|
||||
* @param {string} hostPrefix
|
||||
*/
|
||||
buildXml(hostPrefix) {
|
||||
const blockTags = [{ 'itunes:block': 'yes' }, { 'googleplay:block': 'yes' }]
|
||||
const customElements = [
|
||||
{ language: this.language || 'en' },
|
||||
{ author: this.author || 'advplyr' },
|
||||
{ 'itunes:author': this.author || 'advplyr' },
|
||||
{ 'itunes:type': this.podcastType || 'serial' },
|
||||
{
|
||||
'itunes:image': {
|
||||
_attr: {
|
||||
href: `${hostPrefix}${this.imageURL}`
|
||||
}
|
||||
}
|
||||
},
|
||||
{ 'itunes:explicit': !!this.explicit }
|
||||
]
|
||||
|
||||
if (this.description) {
|
||||
customElements.push({ 'itunes:summary': { _cdata: this.description } })
|
||||
}
|
||||
|
||||
const itunesOwnersData = []
|
||||
if (this.ownerName || this.author) {
|
||||
itunesOwnersData.push({ 'itunes:name': this.ownerName || this.author })
|
||||
}
|
||||
if (this.ownerEmail) {
|
||||
itunesOwnersData.push({ 'itunes:email': this.ownerEmail })
|
||||
}
|
||||
if (itunesOwnersData.length) {
|
||||
customElements.push({
|
||||
'itunes:owner': itunesOwnersData
|
||||
})
|
||||
}
|
||||
|
||||
if (this.preventIndexing) {
|
||||
customElements.push({ 'itunes:block': 'yes' }, { 'googleplay:block': 'yes' })
|
||||
}
|
||||
|
||||
const rssData = {
|
||||
title: this.title,
|
||||
description: this.description || '',
|
||||
@ -571,29 +606,10 @@ class Feed extends Model {
|
||||
image_url: `${hostPrefix}${this.imageURL}`,
|
||||
custom_namespaces: {
|
||||
itunes: 'http://www.itunes.com/dtds/podcast-1.0.dtd',
|
||||
psc: 'http://podlove.org/simple-chapters',
|
||||
podcast: 'https://podcastindex.org/namespace/1.0',
|
||||
googleplay: 'http://www.google.com/schemas/play-podcasts/1.0'
|
||||
},
|
||||
custom_elements: [
|
||||
{ language: this.language || 'en' },
|
||||
{ author: this.author || 'advplyr' },
|
||||
{ 'itunes:author': this.author || 'advplyr' },
|
||||
{ 'itunes:summary': this.description || '' },
|
||||
{ 'itunes:type': this.podcastType },
|
||||
{
|
||||
'itunes:image': {
|
||||
_attr: {
|
||||
href: `${hostPrefix}${this.imageURL}`
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'itunes:owner': [{ 'itunes:name': this.ownerName || this.author || '' }, { 'itunes:email': this.ownerEmail || '' }]
|
||||
},
|
||||
{ 'itunes:explicit': !!this.explicit },
|
||||
...(this.preventIndexing ? blockTags : [])
|
||||
]
|
||||
custom_elements: customElements
|
||||
}
|
||||
|
||||
const rssfeed = new RSS(rssData)
|
||||
|
@ -305,6 +305,21 @@ class FeedEpisode extends Model {
|
||||
* @param {string} hostPrefix
|
||||
*/
|
||||
getRSSData(hostPrefix) {
|
||||
const customElements = [
|
||||
{ 'itunes:author': this.author || null },
|
||||
{ 'itunes:duration': Math.round(Number(this.duration)) },
|
||||
{ 'itunes:summary': this.description || null },
|
||||
{
|
||||
'itunes:explicit': !!this.explicit
|
||||
},
|
||||
{ 'itunes:episodeType': this.episodeType || null },
|
||||
{ 'itunes:season': this.season || null },
|
||||
{ 'itunes:episode': this.episode || null }
|
||||
].filter((element) => {
|
||||
// Remove empty custom elements
|
||||
return Object.values(element)[0] !== null
|
||||
})
|
||||
|
||||
return {
|
||||
title: this.title,
|
||||
description: this.description || '',
|
||||
@ -317,17 +332,7 @@ class FeedEpisode extends Model {
|
||||
type: this.enclosureType,
|
||||
size: this.enclosureSize
|
||||
},
|
||||
custom_elements: [
|
||||
{ 'itunes:author': this.author },
|
||||
{ 'itunes:duration': secondsToTimestamp(this.duration) },
|
||||
{ 'itunes:summary': this.description || '' },
|
||||
{
|
||||
'itunes:explicit': !!this.explicit
|
||||
},
|
||||
{ 'itunes:episodeType': this.episodeType },
|
||||
{ 'itunes:season': this.season },
|
||||
{ 'itunes:episode': this.episode }
|
||||
]
|
||||
custom_elements: customElements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ function secondsToTimestamp(seconds, includeMs = false, alwaysIncludeHours = fal
|
||||
var ms = _seconds - Math.floor(seconds)
|
||||
_seconds = Math.floor(_seconds)
|
||||
|
||||
var msString = '.' + (includeMs ? ms.toFixed(3) : '0.0').split('.')[1]
|
||||
const msString = includeMs ? '.' + ms.toFixed(3).split('.')[1] : ''
|
||||
if (alwaysIncludeHours) {
|
||||
return `${_hours.toString().padStart(2, '0')}:${_minutes.toString().padStart(2, '0')}:${_seconds.toString().padStart(2, '0')}${msString}`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user