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
*/