public void StartDownload(DownloadRequestBM request)
        {
            QueuedDownloadBM download = new QueuedDownloadBM(
                downloadId: request.DownloadId,
                downloadProgress: this.youtubeDl.PrepareDownload(request.MediaUri, request.Format, serviceConfig.DownloadPath)
                );

            runningDownloads.Add(download);
            download.DownloadHandler.PercentageChanged     += (o, e) => this.notifier.Notify(download.DownloadID, download.DownloadHandler.Status, e);
            download.DownloadHandler.DownloadStatusChanged += (o, e) => {
                this.notifier.Notify(download.DownloadID, e, download.DownloadHandler.Percentage);

                if (e == DownloadState.Completed)
                {
                    EventHandler_DownloadCompleted(download);
                }
                else if (e == DownloadState.Failed)
                {
                    string errorOutput = download.DownloadHandler.ErrorMessage.Replace("\r", "\\r").Replace("\n", "\\n");
                    logger.LogError($"Error occurred during download: CommandLine='{download.DownloadHandler.CommandLine}' StdErr='{errorOutput}'");
                }
            };
            download.DownloadHandler.Start();

            this.logger.LogInformation($"Download started with GUID: {download.DownloadID}");
        }
        private async Task StartNewDownloadsFromQueueAsync(CancellationToken cancellationToken)
        {
            await this.requestQueue.WaitForAvailableItemAsync(cancellationToken);

            if (!maintenanceService.IsMaintenanceRunning)
            {
                DownloadRequestBM request = this.requestQueue.Dequeue(cancellationToken);
                downloadManager.StartDownload(request);
            }
        }
Пример #3
0
        public async Task EnqueueDownload(string MediaUri, string MediaFormat)
        {
            MediaFormat targetFormat = YoutubeDownloader.Media.MediaFormat.Video;

            if (MediaFormat == "mp3audio")
            {
                targetFormat = YoutubeDownloader.Media.MediaFormat.MP3Audio;
            }

            Uri mediaUri = new Uri(MediaUri);

            DownloadRequestBM request = new DownloadRequestBM(mediaUri, targetFormat);

            downloadServiceQueue.Enqueue(request);
            this.filenameDatabase.AssignDownloadId(mediaUri, request.DownloadId);

            await Groups.AddToGroupAsync(Context.ConnectionId, request.DownloadId.ToString());

            await Clients.Caller.SendAsync("UseDownloadId", request.DownloadId);
        }