Show current episode download on init and download queue page updates

This commit is contained in:
advplyr 2023-03-05 10:35:34 -06:00
parent 61c759e0c4
commit 022bf9d0ef
10 changed files with 74 additions and 74 deletions

View file

@ -82,11 +82,9 @@ class LibraryController {
return res.json(req.library)
}
async getDownloadQueue(req, res) {
const library = req.library
let queue = this.podcastManager.getDownloadQueueDetails().filter(q => q.libraryId === library.id)
return res.json(queue)
async getEpisodeDownloadQueue(req, res) {
const libraryDownloadQueueDetails = this.podcastManager.getDownloadQueueDetails(req.library.id)
return res.json(libraryDownloadQueueDetails)
}
async update(req, res) {

View file

@ -36,8 +36,11 @@ class LibraryItemController {
}).filter(au => au)
}
} else if (includeEntities.includes('downloads')) {
var downloadsInQueue = this.podcastManager.getEpisodeDownloadsInQueue(req.libraryItem.id)
item.episodesDownloading = downloadsInQueue.map(d => d.toJSONForClient())
const downloadsInQueue = this.podcastManager.getEpisodeDownloadsInQueue(req.libraryItem.id)
item.episodeDownloadsQueued = downloadsInQueue.map(d => d.toJSONForClient())
if (this.podcastManager.currentDownload?.libraryItemId === req.libraryItem.id) {
item.episodesDownloading = [this.podcastManager.currentDownload.toJSONForClient()]
}
}
return res.json(item)

View file

@ -14,8 +14,7 @@ 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");
const Task = require("../objects/Task")
class PodcastManager {
constructor(db, watcher, notificationManager, taskManager) {
@ -60,12 +59,12 @@ class PodcastManager {
newPe.libraryItemId = libraryItem.id
var newPeDl = new PodcastEpisodeDownload()
newPeDl.setData(newPe, libraryItem, isAutoDownload, libraryItem.libraryId)
this.startPodcastEpisodeDownload(newPeDl, libraryItem)
this.startPodcastEpisodeDownload(newPeDl)
})
}
async startPodcastEpisodeDownload(podcastEpisodeDownload, libraryItem) {
SocketAuthority.emitter('download_queue_updated', this.getDownloadQueueDetails())
async startPodcastEpisodeDownload(podcastEpisodeDownload) {
SocketAuthority.emitter('episode_download_queue_updated', this.getDownloadQueueDetails())
if (this.currentDownload) {
this.downloadQueue.push(podcastEpisodeDownload)
SocketAuthority.emitter('episode_download_queued', podcastEpisodeDownload.toJSONForClient())
@ -75,8 +74,8 @@ class PodcastManager {
const task = new Task()
const taskDescription = `Downloading episode "${podcastEpisodeDownload.podcastEpisode.title}".`
const taskData = {
libraryId: libraryItem.libraryId,
libraryItemId: libraryItem.id,
libraryId: podcastEpisodeDownload.libraryId,
libraryItemId: podcastEpisodeDownload.libraryItemId,
}
task.setData('download-podcast-episode', 'Downloading Episode', taskDescription, taskData)
this.taskManager.addTask(task)
@ -94,7 +93,7 @@ class PodcastManager {
await filePerms.setDefault(this.currentDownload.libraryItem.path)
}
var success = await downloadFile(this.currentDownload.url, this.currentDownload.targetPath).then(() => true).catch((error) => {
let success = await downloadFile(this.currentDownload.url, this.currentDownload.targetPath).then(() => true).catch((error) => {
Logger.error(`[PodcastManager] Podcast Episode download failed`, error)
return false
})
@ -117,12 +116,12 @@ class PodcastManager {
this.taskManager.taskFinished(task)
SocketAuthority.emitter('episode_download_finished', this.currentDownload.toJSONForClient())
SocketAuthority.emitter('download_queue_updated', this.getDownloadQueueDetails())
SocketAuthority.emitter('episode_download_queue_updated', this.getDownloadQueueDetails())
this.watcher.removeIgnoreDir(this.currentDownload.libraryItem.path)
this.currentDownload = null
if (this.downloadQueue.length) {
this.startPodcastEpisodeDownload(this.downloadQueue.shift(), libraryItem)
this.startPodcastEpisodeDownload(this.downloadQueue.shift())
}
}
@ -349,21 +348,14 @@ class PodcastManager {
}
}
getDownloadQueueDetails() {
return this.downloadQueue.map(item => {
return {
id: item.id,
libraryId: item.libraryId || null,
libraryItemId: item.libraryItemId || null,
podcastTitle: item.libraryItem.media.metadata.title || null,
podcastExplicit: item.libraryItem.media.metadata.explicit || false,
episodeDisplayTitle: item.podcastEpisode.title || null,
season: item.podcastEpisode.season || null,
episode: item.podcastEpisode.episode || null,
episodeType: item.podcastEpisode.episodeType || 'full',
publishedAt: item.podcastEpisode.publishedAt || null
}
})
getDownloadQueueDetails(libraryId = null) {
let _currentDownload = this.currentDownload
if (libraryId && _currentDownload?.libraryId !== libraryId) _currentDownload = null
return {
currentDownload: _currentDownload?.toJSONForClient(),
queue: this.downloadQueue.filter(item => !libraryId || item.libraryId === libraryId).map(item => item.toJSONForClient())
}
}
}
module.exports = PodcastManager

View file

@ -11,7 +11,6 @@ class PodcastEpisodeDownload {
this.libraryId = null
this.isAutoDownload = false
this.isDownloading = false
this.isFinished = false
this.failed = false
@ -23,20 +22,21 @@ class PodcastEpisodeDownload {
toJSONForClient() {
return {
id: this.id,
episodeDisplayTitle: this.podcastEpisode ? this.podcastEpisode.title : null,
episodeDisplayTitle: this.podcastEpisode?.title ?? null,
url: this.url,
libraryItemId: this.libraryItem ? this.libraryItem.id : null,
libraryItemId: this.libraryItem?.id || null,
libraryId: this.libraryId || null,
isDownloading: this.isDownloading,
isFinished: this.isFinished,
failed: this.failed,
startedAt: this.startedAt,
createdAt: this.createdAt,
finishedAt: this.finishedAt,
season: this.podcastEpisode ? this.podcastEpisode.season : null,
episode: this.podcastEpisode ? this.podcastEpisode.episode : null,
episodeType: this.podcastEpisode ? this.podcastEpisode.episodeType : 'full',
publishedAt: this.podcastEpisode ? this.podcastEpisode.publishedAt : null
podcastTitle: this.libraryItem?.media.metadata.title ?? null,
podcastExplicit: !!this.libraryItem?.media.metadata.explicit,
season: this.podcastEpisode?.season ?? null,
episode: this.podcastEpisode?.episode ?? null,
episodeType: this.podcastEpisode?.episodeType ?? 'full',
publishedAt: this.podcastEpisode?.publishedAt ?? null
}
}

View file

@ -76,7 +76,7 @@ class ApiRouter {
this.router.get('/libraries/:id/items', LibraryController.middleware.bind(this), LibraryController.getLibraryItems.bind(this))
this.router.delete('/libraries/:id/issues', LibraryController.middleware.bind(this), LibraryController.removeLibraryItemsWithIssues.bind(this))
this.router.get('/libraries/:id/downloads', LibraryController.middleware.bind(this), LibraryController.getDownloadQueue.bind(this))
this.router.get('/libraries/:id/episode-downloads', LibraryController.middleware.bind(this), LibraryController.getEpisodeDownloadQueue.bind(this))
this.router.get('/libraries/:id/series', LibraryController.middleware.bind(this), LibraryController.getAllSeriesForLibrary.bind(this))
this.router.get('/libraries/:id/collections', LibraryController.middleware.bind(this), LibraryController.getCollectionsForLibrary.bind(this))
this.router.get('/libraries/:id/playlists', LibraryController.middleware.bind(this), LibraryController.getUserPlaylistsForLibrary.bind(this))