private async Task <Result <bool> > FinalizeDownloadTasks(List <DownloadTask> downloadTasks, int plexAccountId = 0) { if (!downloadTasks.Any()) { return(ResultExtensions.IsEmpty(nameof(downloadTasks)).LogWarning()); } // Get the download folder var downloadFolder = await _folderPathService.GetDownloadFolderAsync(); if (downloadFolder.IsFailed) { return(downloadFolder.ToResult()); } // Get the destination folder var destinationFolder = await _folderPathService.GetDestinationFolderByMediaType(downloadTasks.First().MediaType); if (destinationFolder.IsFailed) { return(destinationFolder.ToResult()); } // Get plex server access token var serverToken = await _plexAuthenticationService.GetPlexServerTokenAsync(downloadTasks.First().PlexServerId, plexAccountId); if (serverToken.IsFailed) { return(serverToken.ToResult()); } foreach (var downloadTask in downloadTasks) { downloadTask.DownloadFolderId = downloadFolder.Value.Id; downloadTask.DownloadFolder = downloadFolder.Value; downloadTask.DestinationFolderId = destinationFolder.Value.Id; downloadTask.DestinationFolder = destinationFolder.Value; downloadTask.ServerToken = serverToken.Value; } return(await _downloadManager.AddToDownloadQueueAsync(downloadTasks)); }