From 9bef06f466e3c9daa489870a5665c194f66e0fe7 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sun, 9 Oct 2022 14:15:07 +0200 Subject: [PATCH] Add DownloadAll for season and series --- src/components/itemContextMenu.js | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/components/itemContextMenu.js b/src/components/itemContextMenu.js index 15980b23ad..9472874158 100644 --- a/src/components/itemContextMenu.js +++ b/src/components/itemContextMenu.js @@ -141,6 +141,14 @@ import toast from './toast/toast'; }); } + if (item.Type === 'Season' || item.Type == 'Series') { + commands.push({ + name: 'Download All', + id: 'downloadall', + icon: 'file_download' + }); + } + if (item.CanDelete && options.deleteItem !== false) { if (item.Type === 'Playlist' || item.Type === 'BoxSet') { commands.push({ @@ -347,6 +355,48 @@ import toast from './toast/toast'; getResolveFunction(getResolveFunction(resolve, id), id)(); }); break; + case 'downloadall': { + const downloadEpisodes = episodes => { + import('../scripts/fileDownloader').then((fileDownloader) => { + const downloads = episodes.map(episode => { + const downloadHref = apiClient.getItemDownloadUrl(episode.Id); + return { + url: downloadHref, + itemId: episode.Id, + serverId: serverId, + title: episode.Name, + filename: episode.Path.replace(/^.*[\\/]/, '') + }; + }); + + fileDownloader.download(downloads); + }); + }; + const downloadSeasons = seasons => { + Promise.all(seasons.map(seasonItem => { + return apiClient.getEpisodes(seasonItem.SeriesId, { + seasonId: seasonItem.Id, + userId: options.user.Id, + Fields: 'CanDownload,Path' + }); + } + )).then(seasons => { + downloadEpisodes([].concat.apply([], seasons.map(season => season.Items))); + }); + }; + + if (item.Type === 'Season') { + downloadSeasons([item]); + } else if (item.Type === 'Series') { + apiClient.getSeasons(item.Id, { + userId: options.user.Id, + Fields: 'ItemCounts' + }).then(seasons => downloadSeasons(seasons.Items)); + } + + getResolveFunction(getResolveFunction(resolve, id), id)(); + break; + } case 'copy-stream': { const downloadHref = apiClient.getItemDownloadUrl(itemId); copy(downloadHref).then(() => {