Skip to content

Commit

Permalink
Merge pull request #3867 from advplyr/feed_generator_updates
Browse files Browse the repository at this point in the history
Updates to generated RSS feed & Fix series/collection feeds
  • Loading branch information
advplyr authored Jan 20, 2025
2 parents f13283b + b816c0e commit 24ce4a2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 34 deletions.
58 changes: 37 additions & 21 deletions server/models/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '',
Expand All @@ -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)
Expand Down
31 changes: 19 additions & 12 deletions server/models/FeedEpisode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 || '',
Expand All @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
Expand Down

0 comments on commit 24ce4a2

Please sign in to comment.