From 3dc848a106e8b3e6b1ffaf31904f708b18be55a2 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 3 Sep 2022 08:06:52 -0500 Subject: [PATCH] Update:Podcast episodes look for new episodes after this date add input to set the max # of episodes to download --- .../components/modals/item/tabs/Episodes.vue | 24 ++++++++++++++++--- client/components/ui/TextInputWithLabel.vue | 5 ++-- server/controllers/PodcastController.js | 4 +++- server/managers/PodcastManager.js | 13 ++++++---- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/client/components/modals/item/tabs/Episodes.vue b/client/components/modals/item/tabs/Episodes.vue index c4f6723f..f8ab2d04 100644 --- a/client/components/modals/item/tabs/Episodes.vue +++ b/client/components/modals/item/tabs/Episodes.vue @@ -2,8 +2,15 @@
- + +
+

Limit

+ + info_outlined + +
+
Check & Download New Episodes
@@ -52,7 +59,8 @@ export default { data() { return { checkingNewEpisodes: false, - lastEpisodeCheckInput: null + lastEpisodeCheckInput: null, + maxEpisodesToDownload: 3 } }, watch: { @@ -89,6 +97,16 @@ export default { if (this.$refs.lastCheckInput) { this.$refs.lastCheckInput.blur() } + if (this.$refs.maxEpisodesInput) { + this.$refs.maxEpisodesInput.blur() + } + + if (this.maxEpisodesToDownload < 0) { + this.maxEpisodesToDownload = 3 + this.$toast.error('Invalid max episodes to download') + return + } + this.checkingNewEpisodes = true const lastEpisodeCheck = new Date(this.lastEpisodeCheckInput).valueOf() @@ -102,7 +120,7 @@ export default { } this.$axios - .$get(`/api/podcasts/${this.libraryItemId}/checknew`) + .$get(`/api/podcasts/${this.libraryItemId}/checknew?limit=${this.maxEpisodesToDownload}`) .then((response) => { if (response.episodes && response.episodes.length) { console.log('New episodes', response.episodes.length) diff --git a/client/components/ui/TextInputWithLabel.vue b/client/components/ui/TextInputWithLabel.vue index 509274e1..f2161526 100644 --- a/client/components/ui/TextInputWithLabel.vue +++ b/client/components/ui/TextInputWithLabel.vue @@ -5,7 +5,7 @@ {{ label }}{{ note }}

- +
@@ -20,7 +20,8 @@ export default { default: 'text' }, readonly: Boolean, - disabled: Boolean + disabled: Boolean, + inputClass: String }, data() { return {} diff --git a/server/controllers/PodcastController.js b/server/controllers/PodcastController.js index 0ac233ee..097f26b2 100644 --- a/server/controllers/PodcastController.js +++ b/server/controllers/PodcastController.js @@ -140,7 +140,9 @@ class PodcastController { return res.status(500).send('Podcast has no rss feed url') } - var newEpisodes = await this.podcastManager.checkAndDownloadNewEpisodes(libraryItem) + const maxEpisodesToDownload = !isNaN(req.query.limit) ? Number(req.query.limit) : 3 + + var newEpisodes = await this.podcastManager.checkAndDownloadNewEpisodes(libraryItem, maxEpisodesToDownload) res.json({ episodes: newEpisodes || [] }) diff --git a/server/managers/PodcastManager.js b/server/managers/PodcastManager.js index f0ade6cf..1402c0b4 100644 --- a/server/managers/PodcastManager.js +++ b/server/managers/PodcastManager.js @@ -221,7 +221,7 @@ class PodcastManager { return libraryItem.media.autoDownloadEpisodes } - async checkPodcastForNewEpisodes(podcastLibraryItem, dateToCheckForEpisodesAfter) { + async checkPodcastForNewEpisodes(podcastLibraryItem, dateToCheckForEpisodesAfter, maxNewEpisodes = 3) { if (!podcastLibraryItem.media.metadata.feedUrl) { Logger.error(`[PodcastManager] checkPodcastForNewEpisodes no feed url for ${podcastLibraryItem.media.metadata.title} (ID: ${podcastLibraryItem.id})`) return false @@ -234,15 +234,18 @@ class PodcastManager { // Filter new and not already has var newEpisodes = feed.episodes.filter(ep => ep.publishedAt > dateToCheckForEpisodesAfter && !podcastLibraryItem.media.checkHasEpisodeByFeedUrl(ep.enclosure.url)) - // Max new episodes for safety = 3 - newEpisodes = newEpisodes.slice(0, 3) + + if (maxNewEpisodes > 0) { + newEpisodes = newEpisodes.slice(0, maxNewEpisodes) + } + return newEpisodes } - async checkAndDownloadNewEpisodes(libraryItem) { + async checkAndDownloadNewEpisodes(libraryItem, maxEpisodesToDownload) { const lastEpisodeCheckDate = new Date(libraryItem.media.lastEpisodeCheck || 0) Logger.info(`[PodcastManager] checkAndDownloadNewEpisodes for "${libraryItem.media.metadata.title}" - Last episode check: ${lastEpisodeCheckDate}`) - var newEpisodes = await this.checkPodcastForNewEpisodes(libraryItem, libraryItem.media.lastEpisodeCheck) + var newEpisodes = await this.checkPodcastForNewEpisodes(libraryItem, libraryItem.media.lastEpisodeCheck, maxEpisodesToDownload) if (newEpisodes.length) { Logger.info(`[PodcastManager] Found ${newEpisodes.length} new episodes for podcast "${libraryItem.media.metadata.title}" - starting download`) this.downloadPodcastEpisodes(libraryItem, newEpisodes, false)