-
+
+
+
+ Check & Download New Episodes
+
Podcast Episodes
@@ -51,10 +51,23 @@ export default {
},
data() {
return {
- checkingNewEpisodes: false
+ checkingNewEpisodes: false,
+ lastEpisodeCheckInput: null
+ }
+ },
+ watch: {
+ lastEpisodeCheck: {
+ handler(newVal) {
+ if (newVal) {
+ this.setLastEpisodeCheckInput()
+ }
+ }
}
},
computed: {
+ userIsAdminOrUp() {
+ return this.$store.getters['user/getIsAdminOrUp']
+ },
autoDownloadEpisodes() {
return !!this.media.autoDownloadEpisodes
},
@@ -72,8 +85,22 @@ export default {
}
},
methods: {
- checkForNewEpisodes() {
+ async checkForNewEpisodes() {
+ if (this.$refs.lastCheckInput) {
+ this.$refs.lastCheckInput.blur()
+ }
this.checkingNewEpisodes = true
+ const lastEpisodeCheck = new Date(this.lastEpisodeCheckInput).valueOf()
+
+ // If last episode check changed then update it first
+ if (lastEpisodeCheck && lastEpisodeCheck !== this.lastEpisodeCheck) {
+ var updateResult = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, { lastEpisodeCheck }).catch((error) => {
+ console.error('Failed to update', error)
+ return false
+ })
+ console.log('updateResult', updateResult)
+ }
+
this.$axios
.$get(`/api/podcasts/${this.libraryItemId}/checknew`)
.then((response) => {
@@ -91,7 +118,13 @@ export default {
this.$toast.error(errorMsg)
this.checkingNewEpisodes = false
})
+ },
+ setLastEpisodeCheckInput() {
+ this.lastEpisodeCheckInput = this.lastEpisodeCheck ? this.$formatDate(this.lastEpisodeCheck, "yyyy-MM-dd'T'HH:mm") : null
}
+ },
+ mounted() {
+ this.setLastEpisodeCheckInput()
}
}
\ No newline at end of file
diff --git a/client/pages/item/_id/index.vue b/client/pages/item/_id/index.vue
index cd08df99..913d48c2 100644
--- a/client/pages/item/_id/index.vue
+++ b/client/pages/item/_id/index.vue
@@ -150,7 +150,8 @@
-
+
+
@@ -210,6 +211,9 @@ export default {
}
},
computed: {
+ userIsAdminOrUp() {
+ return this.$store.getters['user/getIsAdminOrUp']
+ },
isFile() {
return this.libraryItem.isFile
},
diff --git a/client/store/user.js b/client/store/user.js
index c4dca6ef..9cfb0a62 100644
--- a/client/store/user.js
+++ b/client/store/user.js
@@ -16,6 +16,7 @@ export const state = () => ({
export const getters = {
getIsRoot: (state) => state.user && state.user.type === 'root',
+ getIsAdminOrUp: (state) => state.user && (state.user.type === 'admin' || state.user.type === 'root'),
getToken: (state) => {
return state.user ? state.user.token : null
},
diff --git a/server/controllers/PodcastController.js b/server/controllers/PodcastController.js
index a5df7abe..11994f60 100644
--- a/server/controllers/PodcastController.js
+++ b/server/controllers/PodcastController.js
@@ -124,7 +124,7 @@ class PodcastController {
return res.status(500).send('Podcast has no rss feed url')
}
- var newEpisodes = await this.podcastManager.checkPodcastForNewEpisodes(libraryItem)
+ var newEpisodes = await this.podcastManager.checkAndDownloadNewEpisodes(libraryItem)
res.json({
episodes: newEpisodes || []
})
diff --git a/server/managers/PodcastManager.js b/server/managers/PodcastManager.js
index e5878038..7d6922fb 100644
--- a/server/managers/PodcastManager.js
+++ b/server/managers/PodcastManager.js
@@ -208,8 +208,27 @@ class PodcastManager {
}
// Filter new and not already has
var newEpisodes = feed.episodes.filter(ep => ep.publishedAt > podcastLibraryItem.media.lastEpisodeCheck && !podcastLibraryItem.media.checkHasEpisodeByFeedUrl(ep.enclosure.url))
- // Max new episodes for safety = 2
- newEpisodes = newEpisodes.slice(0, 2)
+ // Max new episodes for safety = 3
+ newEpisodes = newEpisodes.slice(0, 3)
+ return newEpisodes
+ }
+
+ async checkAndDownloadNewEpisodes(libraryItem) {
+ 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)
+ if (newEpisodes.length) {
+ Logger.info(`[PodcastManager] Found ${newEpisodes.length} new episodes for podcast "${libraryItem.media.metadata.title}" - starting download`)
+ this.downloadPodcastEpisodes(libraryItem, newEpisodes)
+ } else {
+ Logger.info(`[PodcastManager] No new episodes found for podcast "${libraryItem.media.metadata.title}"`)
+ }
+
+ libraryItem.media.lastEpisodeCheck = Date.now()
+ libraryItem.updatedAt = Date.now()
+ await this.db.updateLibraryItem(libraryItem)
+ this.emitter('item_updated', libraryItem.toJSONExpanded())
+
return newEpisodes
}
diff --git a/server/objects/settings/ServerSettings.js b/server/objects/settings/ServerSettings.js
index 7be8f9de..e1e20e12 100644
--- a/server/objects/settings/ServerSettings.js
+++ b/server/objects/settings/ServerSettings.js
@@ -79,7 +79,7 @@ class ServerSettings {
this.backupSchedule = settings.backupSchedule || false
this.backupsToKeep = settings.backupsToKeep || 2
- this.maxBackupSize = settings.maxBackupSize || 1
+ this.maxBackupSize = settings.maxBackupSize || 1
this.backupMetadataCovers = settings.backupMetadataCovers !== false
this.loggerDailyLogsToKeep = settings.loggerDailyLogsToKeep || 7
diff --git a/server/objects/user/User.js b/server/objects/user/User.js
index 53d97480..16afe944 100644
--- a/server/objects/user/User.js
+++ b/server/objects/user/User.js
@@ -30,6 +30,9 @@ class User {
get isRoot() {
return this.type === 'root'
}
+ get isAdmin() {
+ return this.type === 'admin'
+ }
get canDelete() {
return !!this.permissions.delete && this.isActive
}