Merge pull request #4016 from Ongy/downloadAll

Add DownloadAll for season and series
This commit is contained in:
Bill Thornton 2023-01-04 23:50:08 -05:00 committed by GitHub
commit f5afde5060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 0 deletions

View File

@ -141,6 +141,14 @@ import toast from './toast/toast';
});
}
if (item.Type === 'Season' || item.Type == 'Series') {
commands.push({
name: globalize.translate('DownloadAll'),
id: 'downloadall',
icon: 'file_download'
});
}
if (item.CanDelete && options.deleteItem !== false) {
if (item.Type === 'Playlist' || item.Type === 'BoxSet') {
commands.push({
@ -316,6 +324,7 @@ import toast from './toast/toast';
const apiClient = ServerConnections.getApiClient(serverId);
return new Promise(function (resolve, reject) {
// eslint-disable-next-line sonarjs/max-switch-cases
switch (id) {
case 'addtocollection':
import('./collectionEditor/collectionEditor').then(({default: CollectionEditor}) => {
@ -347,6 +356,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(seasonData => {
downloadEpisodes(seasonData.map(season => season.Items).flat());
});
};
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(() => {

View File

@ -42,6 +42,10 @@ export default {
* @returns true on success
*/
downloadFiles(items) {
if (window.NativeShell?.downloadFiles) {
window.NativeShell.downloadFiles(items);
return true;
}
if (window.NativeShell?.downloadFile) {
items.forEach(item => {
window.NativeShell.downloadFile(item);

View File

@ -208,6 +208,7 @@
"DoNotRecord": "Do not record",
"Down": "Down",
"Download": "Download",
"DownloadAll": "Download All",
"DownloadsValue": "{0} downloads",
"DrmChannelsNotImported": "Channels with DRM will not be imported.",
"DropShadow": "Drop Shadow",