diff --git a/server/models/Feed.js b/server/models/Feed.js index 41bca449cb..577dedfb99 100644 --- a/server/models/Feed.js +++ b/server/models/Feed.js @@ -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) diff --git a/server/models/FeedEpisode.js b/server/models/FeedEpisode.js index 4133f69116..a5fa726297 100644 --- a/server/models/FeedEpisode.js +++ b/server/models/FeedEpisode.js @@ -220,7 +220,7 @@ class FeedEpisode extends Model { const feedEpisodeObjs = [] let numExisting = 0 for (const book of books) { - const trackList = book.libraryItem.getTrackList() + const trackList = book.getTracklist(book.libraryItem.id) const useChapterTitles = this.checkUseChapterTitlesForEpisodes(trackList, book) for (const track of trackList) { // Check for existing episode by filepath @@ -305,6 +305,23 @@ class FeedEpisode extends Model { * @param {string} hostPrefix */ getRSSData(hostPrefix) { + const customElements = [ + { 'itunes:author': this.author || null }, + { 'itunes:duration': Math.round(Number(this.duration)) }, + { + '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 + }) + if (this.description) { + customElements.push({ 'itunes:summary': { _cdata: this.description } }) + } + return { title: this.title, description: this.description || '', @@ -317,17 +334,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 } } } diff --git a/server/utils/index.js b/server/utils/index.js index fa7ae92ed2..a8c0ff54ae 100644 --- a/server/utils/index.js +++ b/server/utils/index.js @@ -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}` }