This commit is contained in:
Rhys Tyers 2023-01-09 21:48:56 +00:00
parent ebedaeb3b0
commit 51b3f0d465
8 changed files with 157 additions and 200 deletions

View file

@ -45,6 +45,9 @@ class PodcastController {
var libraryItemFolderStats = await getFileTimestampsWithIno(podcastPath)
var podcastFeed = await getPodcastFeed(payload.media.metadata.feedUrl)
var podcastFeedDownloadedAt = Date.now()
var relPath = payload.path.replace(folder.fullPath, '')
if (relPath.startsWith('/')) relPath = relPath.slice(1)
@ -57,7 +60,7 @@ class PodcastController {
mtimeMs: libraryItemFolderStats.mtimeMs || 0,
ctimeMs: libraryItemFolderStats.ctimeMs || 0,
birthtimeMs: libraryItemFolderStats.birthtimeMs || 0,
media: payload.media
media: { ...payload.media, podcastFeed, podcastFeedDownloadedAt }
}
var libraryItem = new LibraryItem()
@ -106,6 +109,12 @@ class PodcastController {
res.json({ podcast })
}
async refreshPodcastFeed(req, res) {
var libraryItem = req.libraryItem;
await this.podcastManager.refreshPodcastFeed(libraryItem);
res.json({ episodes: libraryItem.media.episodes });
}
async getOPMLFeeds(req, res) {
if (!req.body.opmlText) {
return res.sendStatus(400)

View file

@ -49,6 +49,13 @@ class PodcastManager {
}
}
async refreshPodcastFeed(libraryItem) {
var feed = await getPodcastFeed(libraryItem.media.metadata.feedUrl);
libraryItem.updatedAt = Date.now();
libraryItem.media.update({podcastFeed: feed, podcastFeedDownloadedAt: Date.now()})
await this.db.updateLibraryItem(libraryItem);
}
async downloadPodcastEpisodes(libraryItem, episodesToDownload, isAutoDownload) {
var index = libraryItem.media.episodes.length + 1
episodesToDownload.forEach((ep) => {

View file

@ -26,6 +26,9 @@ class Podcast {
this.lastCoverSearch = null
this.lastCoverSearchQuery = null
this.podcastFeed = null
this.podcastFeedDownloadedAt = null
if (podcast) {
this.construct(podcast)
}
@ -46,6 +49,8 @@ class Podcast {
this.lastEpisodeCheck = podcast.lastEpisodeCheck || 0
this.maxEpisodesToKeep = podcast.maxEpisodesToKeep || 0
this.maxNewEpisodesToDownload = podcast.maxNewEpisodesToDownload || 3
this.podcastFeed = podcast.podcastFeed
this.podcastFeedDownloadedAt = podcast.podcastFeedDownloadedAt
}
toJSON() {
@ -54,12 +59,14 @@ class Podcast {
metadata: this.metadata.toJSON(),
coverPath: this.coverPath,
tags: [...this.tags],
episodes: this.episodes.map(e => e.toJSON()),
episodes: this.episodes.map((e) => e.toJSON()),
autoDownloadEpisodes: this.autoDownloadEpisodes,
autoDownloadSchedule: this.autoDownloadSchedule,
lastEpisodeCheck: this.lastEpisodeCheck,
maxEpisodesToKeep: this.maxEpisodesToKeep,
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload,
podcastFeed: this.podcastFeed,
podcastFeedDownloadedAt: this.podcastFeedDownloadedAt,
}
}
@ -74,7 +81,9 @@ class Podcast {
lastEpisodeCheck: this.lastEpisodeCheck,
maxEpisodesToKeep: this.maxEpisodesToKeep,
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload,
size: this.size
size: this.size,
podcastFeed: this.podcastFeed,
podcastFeedDownloadedAt: this.podcastFeedDownloadedAt,
}
}
@ -84,13 +93,15 @@ class Podcast {
metadata: this.metadata.toJSONExpanded(),
coverPath: this.coverPath,
tags: [...this.tags],
episodes: this.episodes.map(e => e.toJSONExpanded()),
episodes: this.episodes.map((e) => e.toJSONExpanded()),
autoDownloadEpisodes: this.autoDownloadEpisodes,
autoDownloadSchedule: this.autoDownloadSchedule,
lastEpisodeCheck: this.lastEpisodeCheck,
maxEpisodesToKeep: this.maxEpisodesToKeep,
maxNewEpisodesToDownload: this.maxNewEpisodesToDownload,
size: this.size
size: this.size,
podcastFeed: this.podcastFeed,
podcastFeedDownloadedAt: this.podcastFeedDownloadedAt,
}
}
@ -185,6 +196,9 @@ class Podcast {
this.autoDownloadEpisodes = !!mediaData.autoDownloadEpisodes
this.autoDownloadSchedule = mediaData.autoDownloadSchedule || global.ServerSettings.podcastEpisodeSchedule
this.lastEpisodeCheck = Date.now() // Makes sure new episodes are after this
this.podcastFeed = mediaData.podcastFeed || null
this.podcastFeedDownloadedAt = mediaData.podcastFeedDownloadedAt || null
}
async syncMetadataFiles(textMetadataFiles, opfMetadataOverrideDetails) {

View file

@ -234,7 +234,7 @@ class ApiRouter {
this.router.post('/podcasts/:id/match-episodes', PodcastController.middleware.bind(this), PodcastController.quickMatchEpisodes.bind(this))
this.router.patch('/podcasts/:id/episode/:episodeId', PodcastController.middleware.bind(this), PodcastController.updateEpisode.bind(this))
this.router.delete('/podcasts/:id/episode/:episodeId', PodcastController.middleware.bind(this), PodcastController.removeEpisode.bind(this))
this.router.get('/podcasts/:id/refresh-episodes-list', PodcastController.middleware.bind(this), PodcastController.refreshPodcastFeed.bind(this))
//
// Notification Routes (Admin and up)
//