From d69f6020c6e9d07122e1d7be4f8a75358d442ab5 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 17 Apr 2022 17:52:06 -0500 Subject: [PATCH] Fix podcast episode playback session duration, use podcast episode plaintext description --- client/components/tables/podcast/EpisodeTableRow.vue | 4 +--- server/objects/PlaybackSession.js | 9 +++++++-- server/objects/entities/PodcastEpisode.js | 8 +++++++- server/objects/mediaTypes/Podcast.js | 6 ++++++ server/utils/podcastUtils.js | 10 +++++++++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/client/components/tables/podcast/EpisodeTableRow.vue b/client/components/tables/podcast/EpisodeTableRow.vue index 4f8edf58..da71524f 100644 --- a/client/components/tables/podcast/EpisodeTableRow.vue +++ b/client/components/tables/podcast/EpisodeTableRow.vue @@ -10,9 +10,7 @@

{{ title }}

-

- {{ description }} -

+

{{ description }}

{{ streamIsPlaying ? 'pause' : 'play_arrow' }} diff --git a/server/objects/PlaybackSession.js b/server/objects/PlaybackSession.js index 59e66b46..34311928 100644 --- a/server/objects/PlaybackSession.js +++ b/server/objects/PlaybackSession.js @@ -136,9 +136,14 @@ class PlaybackSession { this.mediaMetadata = libraryItem.media.metadata.clone() this.chapters = (libraryItem.media.chapters || []).map(c => ({ ...c })) // Only book mediaType has chapters this.displayTitle = libraryItem.media.getPlaybackTitle(episodeId) - this.displayAuthor = libraryItem.media.getPlaybackAuthor(episodeId) + this.displayAuthor = libraryItem.media.getPlaybackAuthor() this.coverPath = libraryItem.media.coverPath - this.duration = libraryItem.media.duration + + if (episodeId) { + this.duration = libraryItem.media.getEpisodeDuration(episodeId) + } else { + this.duration = libraryItem.media.duration + } this.mediaPlayer = mediaPlayer diff --git a/server/objects/entities/PodcastEpisode.js b/server/objects/entities/PodcastEpisode.js index 83cd15d2..6c6b956b 100644 --- a/server/objects/entities/PodcastEpisode.js +++ b/server/objects/entities/PodcastEpisode.js @@ -1,3 +1,4 @@ +const { stripHtml } = require('string-strip-html') const { getId } = require('../../utils/index') const AudioFile = require('../files/AudioFile') const AudioTrack = require('../files/AudioTrack') @@ -73,7 +74,8 @@ class PodcastEpisode { episodeType: this.episodeType, title: this.title, subtitle: this.subtitle, - description: this.description, + // description: this.description, + description: this.descriptionPlain, // Temporary stripping HTML until proper cleaning is implemented enclosure: this.enclosure ? { ...this.enclosure } : null, pubDate: this.pubDate, audioFile: this.audioFile.toJSON(), @@ -102,6 +104,10 @@ class PodcastEpisode { if (this.episode) return `${this.episode} - ${this.title}` return this.title } + get descriptionPlain() { + if (!this.description) return '' + return stripHtml(this.description).result + } setData(data, index = 1) { this.id = getId('ep') diff --git a/server/objects/mediaTypes/Podcast.js b/server/objects/mediaTypes/Podcast.js index b9a1be0e..fd62a4f2 100644 --- a/server/objects/mediaTypes/Podcast.js +++ b/server/objects/mediaTypes/Podcast.js @@ -251,5 +251,11 @@ class Podcast { getPlaybackAuthor() { return this.metadata.author } + + getEpisodeDuration(episodeId) { + var episode = this.episodes.find(ep => ep.id == episodeId) + if (!episode) return 0 + return episode.duration + } } module.exports = Podcast \ No newline at end of file diff --git a/server/utils/podcastUtils.js b/server/utils/podcastUtils.js index a0869c81..69cc2459 100644 --- a/server/utils/podcastUtils.js +++ b/server/utils/podcastUtils.js @@ -73,12 +73,19 @@ function extractEpisodeData(item) { Logger.error(`[podcastUtils] Invalid podcast episode data`) return null } - var arrayFields = ['title', 'pubDate', 'description', 'itunes:episodeType', 'itunes:episode', 'itunes:author', 'itunes:duration', 'itunes:explicit', 'itunes:subtitle'] + var episode = { enclosure: { ...item.enclosure[0]['$'] } } + + if (item['description']) { + episode.description = extractFirstArrayItem(item, 'description') + episode.descriptionPlain = stripHtml(episode.description || '').result + } + + var arrayFields = ['title', 'pubDate', 'itunes:episodeType', 'itunes:episode', 'itunes:author', 'itunes:duration', 'itunes:explicit', 'itunes:subtitle'] arrayFields.forEach((key) => { var cleanKey = key.split(':').pop() episode[cleanKey] = extractFirstArrayItem(item, key) @@ -91,6 +98,7 @@ function cleanEpisodeData(data) { title: data.title, subtitle: data.subtitle || '', description: data.description || '', + descriptionPlain: data.descriptionPlain || '', pubDate: data.pubDate || '', episodeType: data.episodeType || '', episode: data.episode || '',