Update podcasts to new library item model

This commit is contained in:
advplyr 2025-01-03 16:48:24 -06:00
parent 0357dc90d4
commit 69d1744496
11 changed files with 235 additions and 141 deletions

View file

@ -259,6 +259,10 @@ class Podcast extends Model {
this.autoDownloadSchedule = payload.autoDownloadSchedule
hasUpdates = true
}
if (typeof payload.lastEpisodeCheck === 'number' && payload.lastEpisodeCheck !== this.lastEpisodeCheck?.valueOf()) {
this.lastEpisodeCheck = payload.lastEpisodeCheck
hasUpdates = true
}
const numberKeys = ['maxEpisodesToKeep', 'maxNewEpisodesToDownload']
numberKeys.forEach((key) => {
@ -348,6 +352,31 @@ class Podcast extends Model {
return episode.duration
}
/**
*
* @returns {number} - Unix timestamp
*/
getLatestEpisodePublishedAt() {
return this.podcastEpisodes.reduce((latest, episode) => {
if (episode.publishedAt?.valueOf() > latest) {
return episode.publishedAt.valueOf()
}
return latest
}, 0)
}
/**
* Used for checking if an rss feed episode is already in the podcast
*
* @param {Object} feedEpisode - object from rss feed
* @returns {boolean}
*/
checkHasEpisodeByFeedEpisode(feedEpisode) {
const guid = feedEpisode.guid
const url = feedEpisode.enclosure.url
return this.podcastEpisodes.some((ep) => ep.checkMatchesGuidOrEnclosureUrl(guid, url))
}
/**
* Old model kept metadata in a separate object
*/

View file

@ -143,6 +143,23 @@ class PodcastEpisode extends Model {
return this.audioFile?.duration || 0
}
/**
* Used for matching the episode with an episode in the RSS feed
*
* @param {string} guid
* @param {string} enclosureURL
* @returns {boolean}
*/
checkMatchesGuidOrEnclosureUrl(guid, enclosureURL) {
if (this.extraData?.guid && this.extraData.guid === guid) {
return true
}
if (this.enclosureURL && this.enclosureURL === enclosureURL) {
return true
}
return false
}
/**
* Used in client players
*