diff --git a/client/components/cards/ItemTaskRunningCard.vue b/client/components/cards/ItemTaskRunningCard.vue new file mode 100644 index 00000000..f7ee4095 --- /dev/null +++ b/client/components/cards/ItemTaskRunningCard.vue @@ -0,0 +1,85 @@ + + + + + diff --git a/client/components/widgets/NotificationWidget.vue b/client/components/widgets/NotificationWidget.vue index 6c3e82fd..f1fd6dc6 100644 --- a/client/components/widgets/NotificationWidget.vue +++ b/client/components/widgets/NotificationWidget.vue @@ -1,15 +1,51 @@ \ No newline at end of file + + + diff --git a/client/pages/library/_library/podcast/download-queue.vue b/client/pages/library/_library/podcast/download-queue.vue index 11785887..53160c73 100644 --- a/client/pages/library/_library/podcast/download-queue.vue +++ b/client/pages/library/_library/podcast/download-queue.vue @@ -57,6 +57,15 @@ import DownloadQueueTable from "~/components/tables/podcast/DownloadQueueTable.v export default { components: {DownloadQueueTable}, + async asyncData({ params, redirect }) { + if (!params.library) { + console.error('No library...', params.library) + return redirect('/') + } + return { + libraryId: params.library + } + }, data() { return { episodesDownloading: [], @@ -70,45 +79,44 @@ export default { }, streamLibraryItem() { return this.$store.state.streamLibraryItem - }, - currentLibraryId() { - return this.$store.state.libraries.currentLibraryId } }, methods: { episodeDownloadQueued(episodeDownload) { - if (episodeDownload.libraryId === this.currentLibraryId) { + if (episodeDownload.libraryId === this.libraryId) { this.episodeDownloadsQueued.push(episodeDownload) } }, episodeDownloadStarted(episodeDownload) { - if (episodeDownload.libraryId === this.currentLibraryId) { + if (episodeDownload.libraryId === this.libraryId) { this.episodeDownloadsQueued = this.episodeDownloadsQueued.filter((d) => d.id !== episodeDownload.id) this.episodesDownloading.push(episodeDownload) } }, episodeDownloadFinished(episodeDownload) { - if (episodeDownload.libraryId === this.currentLibraryId) { + if (episodeDownload.libraryId === this.libraryId) { this.episodeDownloadsQueued = this.episodeDownloadsQueued.filter((d) => d.id !== episodeDownload.id) this.episodesDownloading = this.episodesDownloading.filter((d) => d.id !== episodeDownload.id) } }, downloadQueueUpdated(downloadQueue) { - this.episodeDownloadsQueued = downloadQueue.filter((q) => q.libraryId == this.currentLibraryId) + this.episodeDownloadsQueued = downloadQueue.filter((q) => q.libraryId == this.libraryId) }, async loadInitialDownloadQueue() { this.processing = true - const queuePayload = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/downloads`).catch((error) => { + const queuePayload = await this.$axios.$get(`/api/libraries/${this.libraryId}/downloads`).catch((error) => { console.error('Failed to get download queue', error) this.$toast.error('Failed to get download queue') return null }) this.processing = false - console.log('Episodes', queuePayload) this.episodeDownloadsQueued = queuePayload || [] } }, mounted() { + if (this.libraryId) { + this.$store.commit('libraries/setCurrentLibrary', this.libraryId) + } this.loadInitialDownloadQueue() this.$root.socket.on('episode_download_queued', this.episodeDownloadQueued) this.$root.socket.on('episode_download_started', this.episodeDownloadStarted) diff --git a/client/strings/de.json b/client/strings/de.json index e1c3b02f..32de2cfe 100644 --- a/client/strings/de.json +++ b/client/strings/de.json @@ -395,6 +395,7 @@ "LabelTag": "Schlagwort", "LabelTags": "Schlagwörter", "LabelTagsAccessibleToUser": "Für Benutzer zugängliche Schlagwörter", + "LabelTasks": "Tasks Running", "LabelTimeListened": "Gehörte Zeit", "LabelTimeListenedToday": "Heute gehörte Zeit", "LabelTimeRemaining": "{0} verbleibend", @@ -514,6 +515,7 @@ "MessageNoSearchResultsFor": "Keine Suchergebnisse für \"{0}\"", "MessageNoSeries": "Keine Serien", "MessageNoTags": "Keine Tags", + "MessageNoTasksRunning": "No Tasks Running", "MessageNotYetImplemented": "Noch nicht implementiert", "MessageNoUpdateNecessary": "Keine Aktualisierung erforderlich", "MessageNoUpdatesWereNecessary": "Keine Aktualisierungen waren notwendig", diff --git a/client/strings/en-us.json b/client/strings/en-us.json index c8e87d28..a76db534 100644 --- a/client/strings/en-us.json +++ b/client/strings/en-us.json @@ -395,6 +395,7 @@ "LabelTag": "Tag", "LabelTags": "Tags", "LabelTagsAccessibleToUser": "Tags Accessible to User", + "LabelTasks": "Tasks Running", "LabelTimeListened": "Time Listened", "LabelTimeListenedToday": "Time Listened Today", "LabelTimeRemaining": "{0} remaining", @@ -514,6 +515,7 @@ "MessageNoSearchResultsFor": "No search results for \"{0}\"", "MessageNoSeries": "No Series", "MessageNoTags": "No Tags", + "MessageNoTasksRunning": "No Tasks Running", "MessageNotYetImplemented": "Not yet implemented", "MessageNoUpdateNecessary": "No update necessary", "MessageNoUpdatesWereNecessary": "No updates were necessary", diff --git a/client/strings/es.json b/client/strings/es.json index c8e87d28..a76db534 100644 --- a/client/strings/es.json +++ b/client/strings/es.json @@ -395,6 +395,7 @@ "LabelTag": "Tag", "LabelTags": "Tags", "LabelTagsAccessibleToUser": "Tags Accessible to User", + "LabelTasks": "Tasks Running", "LabelTimeListened": "Time Listened", "LabelTimeListenedToday": "Time Listened Today", "LabelTimeRemaining": "{0} remaining", @@ -514,6 +515,7 @@ "MessageNoSearchResultsFor": "No search results for \"{0}\"", "MessageNoSeries": "No Series", "MessageNoTags": "No Tags", + "MessageNoTasksRunning": "No Tasks Running", "MessageNotYetImplemented": "Not yet implemented", "MessageNoUpdateNecessary": "No update necessary", "MessageNoUpdatesWereNecessary": "No updates were necessary", diff --git a/client/strings/fr.json b/client/strings/fr.json index 2393110b..a4cdbfc9 100644 --- a/client/strings/fr.json +++ b/client/strings/fr.json @@ -395,6 +395,7 @@ "LabelTag": "Étiquette", "LabelTags": "Étiquettes", "LabelTagsAccessibleToUser": "Étiquettes accessibles à l'utilisateur", + "LabelTasks": "Tasks Running", "LabelTimeListened": "Temps d'écoute", "LabelTimeListenedToday": "Nombres d'écoutes Aujourd'hui", "LabelTimeRemaining": "{0} restantes", @@ -514,6 +515,7 @@ "MessageNoSearchResultsFor": "Pas de résultats de recherche pour \"{0}\"", "MessageNoSeries": "Pas de séries", "MessageNoTags": "Pas d'étiquettes", + "MessageNoTasksRunning": "No Tasks Running", "MessageNotYetImplemented": "Non implémenté", "MessageNoUpdateNecessary": "Pas de mise à jour nécessaire", "MessageNoUpdatesWereNecessary": "Aucune mise à jour n'était nécessaire", diff --git a/client/strings/hr.json b/client/strings/hr.json index 00d27566..404c4d78 100644 --- a/client/strings/hr.json +++ b/client/strings/hr.json @@ -395,6 +395,7 @@ "LabelTag": "Tag", "LabelTags": "Tags", "LabelTagsAccessibleToUser": "Tags dostupni korisniku", + "LabelTasks": "Tasks Running", "LabelTimeListened": "Vremena odslušano", "LabelTimeListenedToday": "Vremena odslušano danas", "LabelTimeRemaining": "{0} preostalo", @@ -514,6 +515,7 @@ "MessageNoSearchResultsFor": "Nema rezultata pretragee za \"{0}\"", "MessageNoSeries": "No Series", "MessageNoTags": "No Tags", + "MessageNoTasksRunning": "No Tasks Running", "MessageNotYetImplemented": "Not yet implemented", "MessageNoUpdateNecessary": "Aktualiziranje nije potrebno", "MessageNoUpdatesWereNecessary": "Aktualiziranje nije bilo potrebno", diff --git a/client/strings/it.json b/client/strings/it.json index 8818f8fd..f6c2b528 100644 --- a/client/strings/it.json +++ b/client/strings/it.json @@ -395,6 +395,7 @@ "LabelTag": "Tag", "LabelTags": "Tags", "LabelTagsAccessibleToUser": "Tags permessi agli Utenti", + "LabelTasks": "Tasks Running", "LabelTimeListened": "Tempo di Ascolto", "LabelTimeListenedToday": "Tempo di Ascolto Oggi", "LabelTimeRemaining": "{0} rimanente", @@ -514,6 +515,7 @@ "MessageNoSearchResultsFor": "Nessun risultato per \"{0}\"", "MessageNoSeries": "Nessuna Serie", "MessageNoTags": "No Tags", + "MessageNoTasksRunning": "No Tasks Running", "MessageNotYetImplemented": "Non Ancora Implementato", "MessageNoUpdateNecessary": "Nessun aggiornamento necessario", "MessageNoUpdatesWereNecessary": "Nessun aggiornamento necessario", diff --git a/client/strings/pl.json b/client/strings/pl.json index 4ecdcff9..db18a20f 100644 --- a/client/strings/pl.json +++ b/client/strings/pl.json @@ -395,6 +395,7 @@ "LabelTag": "Tag", "LabelTags": "Tagi", "LabelTagsAccessibleToUser": "Tagi dostępne dla użytkownika", + "LabelTasks": "Tasks Running", "LabelTimeListened": "Czas odtwarzania", "LabelTimeListenedToday": "Czas odtwarzania dzisiaj", "LabelTimeRemaining": "Pozostało {0}", @@ -514,6 +515,7 @@ "MessageNoSearchResultsFor": "Brak wyników wyszukiwania dla \"{0}\"", "MessageNoSeries": "No Series", "MessageNoTags": "No Tags", + "MessageNoTasksRunning": "No Tasks Running", "MessageNotYetImplemented": "Jeszcze nie zaimplementowane", "MessageNoUpdateNecessary": "Brak konieczności aktualizacji", "MessageNoUpdatesWereNecessary": "Brak aktualizacji", diff --git a/client/strings/ru.json b/client/strings/ru.json index dd50a169..dd5d36d2 100644 --- a/client/strings/ru.json +++ b/client/strings/ru.json @@ -395,6 +395,7 @@ "LabelTag": "Тег", "LabelTags": "Теги", "LabelTagsAccessibleToUser": "Теги Доступные для Пользователя", + "LabelTasks": "Tasks Running", "LabelTimeListened": "Время Прослушивания", "LabelTimeListenedToday": "Время Прослушивания Сегодня", "LabelTimeRemaining": "{0} осталось", @@ -514,6 +515,7 @@ "MessageNoSearchResultsFor": "Нет результатов поиска для \"{0}\"", "MessageNoSeries": "Нет Серий", "MessageNoTags": "Нет Тегов", + "MessageNoTasksRunning": "No Tasks Running", "MessageNotYetImplemented": "Пока не реализовано", "MessageNoUpdateNecessary": "Обновление не требуется", "MessageNoUpdatesWereNecessary": "Обновления не требовались", diff --git a/client/strings/zh-cn.json b/client/strings/zh-cn.json index 671fde5a..16234d90 100644 --- a/client/strings/zh-cn.json +++ b/client/strings/zh-cn.json @@ -395,6 +395,7 @@ "LabelTag": "标签", "LabelTags": "标签", "LabelTagsAccessibleToUser": "用户可访问的标签", + "LabelTasks": "Tasks Running", "LabelTimeListened": "收听时间", "LabelTimeListenedToday": "今日收听的时间", "LabelTimeRemaining": "剩余 {0}", @@ -514,6 +515,7 @@ "MessageNoSearchResultsFor": "没有搜索到结果 \"{0}\"", "MessageNoSeries": "无系列", "MessageNoTags": "无标签", + "MessageNoTasksRunning": "No Tasks Running", "MessageNotYetImplemented": "尚未实施", "MessageNoUpdateNecessary": "无需更新", "MessageNoUpdatesWereNecessary": "无需更新", diff --git a/server/Server.js b/server/Server.js index a5a0b8b5..4a900a68 100644 --- a/server/Server.js +++ b/server/Server.js @@ -72,7 +72,7 @@ class Server { this.abMergeManager = new AbMergeManager(this.db, this.taskManager) this.playbackSessionManager = new PlaybackSessionManager(this.db) this.coverManager = new CoverManager(this.db, this.cacheManager) - this.podcastManager = new PodcastManager(this.db, this.watcher, this.notificationManager) + this.podcastManager = new PodcastManager(this.db, this.watcher, this.notificationManager, this.taskManager) this.audioMetadataManager = new AudioMetadataMangaer(this.db, this.taskManager) this.rssFeedManager = new RssFeedManager(this.db) this.eBookManager = new EBookManager(this.db) diff --git a/server/managers/PodcastManager.js b/server/managers/PodcastManager.js index 3b7e352b..6c974591 100644 --- a/server/managers/PodcastManager.js +++ b/server/managers/PodcastManager.js @@ -14,12 +14,15 @@ const LibraryFile = require('../objects/files/LibraryFile') const PodcastEpisodeDownload = require('../objects/PodcastEpisodeDownload') const PodcastEpisode = require('../objects/entities/PodcastEpisode') const AudioFile = require('../objects/files/AudioFile') +const Task = require("../objects/Task"); +const Path = require("path"); class PodcastManager { - constructor(db, watcher, notificationManager) { + constructor(db, watcher, notificationManager, taskManager) { this.db = db this.watcher = watcher this.notificationManager = notificationManager + this.taskManager = taskManager this.downloadQueue = [] this.currentDownload = null @@ -57,11 +60,11 @@ class PodcastManager { newPe.libraryItemId = libraryItem.id var newPeDl = new PodcastEpisodeDownload() newPeDl.setData(newPe, libraryItem, isAutoDownload, libraryItem.libraryId) - this.startPodcastEpisodeDownload(newPeDl) + this.startPodcastEpisodeDownload(newPeDl, libraryItem) }) } - async startPodcastEpisodeDownload(podcastEpisodeDownload) { + async startPodcastEpisodeDownload(podcastEpisodeDownload, libraryItem) { SocketAuthority.emitter('download_queue_updated', this.getDownloadQueueDetails()) if (this.currentDownload) { this.downloadQueue.push(podcastEpisodeDownload) @@ -69,6 +72,15 @@ class PodcastManager { return } + const task = new Task() + const taskDescription = `Downloading episode "${podcastEpisodeDownload.podcastEpisode.title}".` + const taskData = { + libraryId: libraryItem.libraryId, + libraryItemId: libraryItem.id, + } + task.setData('download-podcast-episode', 'Downloading Episode', taskDescription, taskData) + this.taskManager.addTask(task) + SocketAuthority.emitter('episode_download_started', podcastEpisodeDownload.toJSONForClient()) this.currentDownload = podcastEpisodeDownload @@ -91,21 +103,26 @@ class PodcastManager { if (!success) { await fs.remove(this.currentDownload.targetPath) this.currentDownload.setFinished(false) + task.setFailed('Failed to download episode') } else { Logger.info(`[PodcastManager] Successfully downloaded podcast episode "${this.currentDownload.podcastEpisode.title}"`) this.currentDownload.setFinished(true) + task.setFinished() } } else { + task.setFailed('Failed to download episode') this.currentDownload.setFinished(false) } + this.taskManager.taskFinished(task) + SocketAuthority.emitter('episode_download_finished', this.currentDownload.toJSONForClient()) SocketAuthority.emitter('download_queue_updated', this.getDownloadQueueDetails()) this.watcher.removeIgnoreDir(this.currentDownload.libraryItem.path) this.currentDownload = null if (this.downloadQueue.length) { - this.startPodcastEpisodeDownload(this.downloadQueue.shift()) + this.startPodcastEpisodeDownload(this.downloadQueue.shift(), libraryItem) } }