From 5e7bca02b3768a0b270e7a2124532816de780cc8 Mon Sep 17 00:00:00 2001 From: Spenser Bushey Date: Wed, 23 Nov 2022 22:36:07 -0800 Subject: [PATCH 1/3] RSS feeds for single file audiobooks now use book title --- server/objects/Feed.js | 6 +++++- server/objects/FeedEpisode.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/server/objects/Feed.js b/server/objects/Feed.js index 9e00d57c..e3b54fed 100644 --- a/server/objects/Feed.js +++ b/server/objects/Feed.js @@ -101,7 +101,11 @@ class Feed { feedEpisode.setFromPodcastEpisode(libraryItem, serverAddress, slug, episode, this.meta) this.episodes.push(feedEpisode) }) - } else { // AUDIOBOOK EPISODES + } else if (media.tracks.length == 1) { // SINGLE FILE AUDIOBOOKS + var feedEpisode = new FeedEpisode() + feedEpisode.setFromSingleAudiobookTrack(libraryItem, serverAddress, slug, media.tracks[0], this.meta) + this.episodes.push(feedEpisode) + } else { // MULTI-FILE AUDIOBOOKS media.tracks.forEach((audioTrack) => { var feedEpisode = new FeedEpisode() feedEpisode.setFromAudiobookTrack(libraryItem, serverAddress, slug, audioTrack, this.meta) diff --git a/server/objects/FeedEpisode.js b/server/objects/FeedEpisode.js index 28a60e78..8c166bfc 100644 --- a/server/objects/FeedEpisode.js +++ b/server/objects/FeedEpisode.js @@ -118,6 +118,35 @@ class FeedEpisode { this.fullPath = audioTrack.metadata.path } + setFromSingleAudiobookTrack(libraryItem, serverAddress, slug, audioTrack, meta) { + // Example: Fri, 04 Feb 2015 00:00:00 GMT + const audiobookPubDate = date.format(new Date(libraryItem.addedAt), 'ddd, DD MMM YYYY HH:mm:ss [GMT]') + + const contentUrl = `/feed/${slug}/item/${audioTrack.index}/${audioTrack.metadata.filename}` + const media = libraryItem.media + const mediaMetadata = media.metadata + + var title = libraryItem.media.metadata.title + + this.id = String(audioTrack.index) + this.title = title + this.description = mediaMetadata.description || '' + this.enclosure = { + url: `${serverAddress}${contentUrl}`, + type: audioTrack.mimeType, + size: audioTrack.metadata.size + } + this.pubDate = audiobookPubDate + this.link = meta.link + this.author = meta.author + this.explicit = mediaMetadata.explicit + this.duration = audioTrack.duration + this.libraryItemId = libraryItem.id + this.episodeId = null + this.trackIndex = audioTrack.index + this.fullPath = audioTrack.metadata.path + } + getRSSData() { return { title: this.title, From 12abb1731c8137b03fb6db207f84ec0d81cfaad3 Mon Sep 17 00:00:00 2001 From: Spenser Bushey Date: Thu, 24 Nov 2022 23:10:20 -0800 Subject: [PATCH 2/3] Single file audiobook rss feed naming logic moved to FeedEpisode.js --- server/objects/Feed.js | 6 +---- server/objects/FeedEpisode.js | 43 ++++++++--------------------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/server/objects/Feed.js b/server/objects/Feed.js index e3b54fed..9e00d57c 100644 --- a/server/objects/Feed.js +++ b/server/objects/Feed.js @@ -101,11 +101,7 @@ class Feed { feedEpisode.setFromPodcastEpisode(libraryItem, serverAddress, slug, episode, this.meta) this.episodes.push(feedEpisode) }) - } else if (media.tracks.length == 1) { // SINGLE FILE AUDIOBOOKS - var feedEpisode = new FeedEpisode() - feedEpisode.setFromSingleAudiobookTrack(libraryItem, serverAddress, slug, media.tracks[0], this.meta) - this.episodes.push(feedEpisode) - } else { // MULTI-FILE AUDIOBOOKS + } else { // AUDIOBOOK EPISODES media.tracks.forEach((audioTrack) => { var feedEpisode = new FeedEpisode() feedEpisode.setFromAudiobookTrack(libraryItem, serverAddress, slug, audioTrack, this.meta) diff --git a/server/objects/FeedEpisode.js b/server/objects/FeedEpisode.js index 8c166bfc..0affca84 100644 --- a/server/objects/FeedEpisode.js +++ b/server/objects/FeedEpisode.js @@ -92,11 +92,15 @@ class FeedEpisode { const media = libraryItem.media const mediaMetadata = media.metadata - var title = audioTrack.title - if (libraryItem.media.chapters.length) { - // If audio track start and chapter start are within 1 seconds of eachother then use the chapter title - var matchingChapter = libraryItem.media.chapters.find(ch => Math.abs(ch.start - audioTrack.startOffset) < 1) - if (matchingChapter && matchingChapter.title) title = matchingChapter.title + if (libraryItem.media.tracks.length == 1) { // If audiobook is a single file, use book title instead of chapter/file title + var title = libraryItem.media.metadata.title + } else { + var title = audioTrack.title + if (libraryItem.media.chapters.length) { + // If audio track start and chapter start are within 1 seconds of eachother then use the chapter title + var matchingChapter = libraryItem.media.chapters.find(ch => Math.abs(ch.start - audioTrack.startOffset) < 1) + if (matchingChapter && matchingChapter.title) title = matchingChapter.title + } } this.id = String(audioTrack.index) @@ -118,35 +122,6 @@ class FeedEpisode { this.fullPath = audioTrack.metadata.path } - setFromSingleAudiobookTrack(libraryItem, serverAddress, slug, audioTrack, meta) { - // Example: Fri, 04 Feb 2015 00:00:00 GMT - const audiobookPubDate = date.format(new Date(libraryItem.addedAt), 'ddd, DD MMM YYYY HH:mm:ss [GMT]') - - const contentUrl = `/feed/${slug}/item/${audioTrack.index}/${audioTrack.metadata.filename}` - const media = libraryItem.media - const mediaMetadata = media.metadata - - var title = libraryItem.media.metadata.title - - this.id = String(audioTrack.index) - this.title = title - this.description = mediaMetadata.description || '' - this.enclosure = { - url: `${serverAddress}${contentUrl}`, - type: audioTrack.mimeType, - size: audioTrack.metadata.size - } - this.pubDate = audiobookPubDate - this.link = meta.link - this.author = meta.author - this.explicit = mediaMetadata.explicit - this.duration = audioTrack.duration - this.libraryItemId = libraryItem.id - this.episodeId = null - this.trackIndex = audioTrack.index - this.fullPath = audioTrack.metadata.path - } - getRSSData() { return { title: this.title, From df7e331605bcead559bf8d0b9890b263d00c8a32 Mon Sep 17 00:00:00 2001 From: advplyr <67830747+advplyr@users.noreply.github.com> Date: Fri, 25 Nov 2022 06:21:50 -0600 Subject: [PATCH 3/3] Update server/objects/FeedEpisode.js --- server/objects/FeedEpisode.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/objects/FeedEpisode.js b/server/objects/FeedEpisode.js index 0affca84..ed3a7e21 100644 --- a/server/objects/FeedEpisode.js +++ b/server/objects/FeedEpisode.js @@ -92,10 +92,10 @@ class FeedEpisode { const media = libraryItem.media const mediaMetadata = media.metadata + let title = audioTrack.title if (libraryItem.media.tracks.length == 1) { // If audiobook is a single file, use book title instead of chapter/file title - var title = libraryItem.media.metadata.title + title = libraryItem.media.metadata.title } else { - var title = audioTrack.title if (libraryItem.media.chapters.length) { // If audio track start and chapter start are within 1 seconds of eachother then use the chapter title var matchingChapter = libraryItem.media.chapters.find(ch => Math.abs(ch.start - audioTrack.startOffset) < 1)