Add download queue

This commit is contained in:
mfcar 2023-02-27 02:56:07 +00:00
parent f0edea5d52
commit 34ac972130
No known key found for this signature in database
21 changed files with 359 additions and 22 deletions

View file

@ -82,6 +82,13 @@ 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 update(req, res) {
const library = req.library

View file

@ -56,12 +56,13 @@ class PodcastManager {
newPe.setData(ep, index++)
newPe.libraryItemId = libraryItem.id
var newPeDl = new PodcastEpisodeDownload()
newPeDl.setData(newPe, libraryItem, isAutoDownload)
newPeDl.setData(newPe, libraryItem, isAutoDownload, libraryItem.libraryId)
this.startPodcastEpisodeDownload(newPeDl)
})
}
async startPodcastEpisodeDownload(podcastEpisodeDownload) {
SocketAuthority.emitter('download_queue_updated', this.getDownloadQueueDetails())
if (this.currentDownload) {
this.downloadQueue.push(podcastEpisodeDownload)
SocketAuthority.emitter('episode_download_queued', podcastEpisodeDownload.toJSONForClient())
@ -99,6 +100,7 @@ class PodcastManager {
}
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
@ -329,5 +331,22 @@ class PodcastManager {
feeds: rssFeedData
}
}
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
}
})
}
}
module.exports = PodcastManager
module.exports = PodcastManager

View file

@ -8,6 +8,7 @@ class PodcastEpisodeDownload {
this.podcastEpisode = null
this.url = null
this.libraryItem = null
this.libraryId = null
this.isAutoDownload = false
this.isDownloading = false
@ -25,12 +26,17 @@ class PodcastEpisodeDownload {
episodeDisplayTitle: this.podcastEpisode ? this.podcastEpisode.title : null,
url: this.url,
libraryItemId: this.libraryItem ? 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
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
}
}
@ -47,13 +53,14 @@ class PodcastEpisodeDownload {
return this.libraryItem ? this.libraryItem.id : null
}
setData(podcastEpisode, libraryItem, isAutoDownload) {
setData(podcastEpisode, libraryItem, isAutoDownload, libraryId) {
this.id = getId('epdl')
this.podcastEpisode = podcastEpisode
this.url = encodeURI(podcastEpisode.enclosure.url)
this.libraryItem = libraryItem
this.isAutoDownload = isAutoDownload
this.createdAt = Date.now()
this.libraryId = libraryId
}
setFinished(success) {
@ -62,4 +69,4 @@ class PodcastEpisodeDownload {
this.failed = !success
}
}
module.exports = PodcastEpisodeDownload
module.exports = PodcastEpisodeDownload

View file

@ -76,6 +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/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))
@ -553,4 +554,4 @@ class ApiRouter {
}
}
}
module.exports = ApiRouter
module.exports = ApiRouter