private async Task <VideoDTO> DownloadRemoteVideoFileAsync(RemoteVideoFile file) { if (this.client.StartVideoDownload(file)) { DateTime downloadStarted = DateTime.Now; do { await Task.Delay(this.ProgressCheckPeriodMilliseconds); this.cancelTokenSource.Token.ThrowIfCancellationRequested(); this.client.UpdateVideoProgress(); }while (this.client.IsDownloading); TimeSpan duration = DateTime.Now - downloadStarted; this.logger.Info($"Download duration {duration.ToString(DurationFormat)}, avg speed {Utils.FormatBytes((long)(file.Size / duration.TotalSeconds))}/s"); return(new VideoDTO { Size = file.Size, Name = file.Name, StartTime = file.StartTime, StopTime = file.StopTime, DownloadStartTime = downloadStarted, DownloadStopTime = DateTime.Now, }); } return(default(VideoDTO)); }
public bool StartVideoDownload(RemoteVideoFile remoteFile) { if (!this.IsDownloading) { string destinationFilePath = this.GetPathSafety(remoteFile); if (!this.CheckLocalVideoExist(destinationFilePath, remoteFile.Size)) { this.downloadId = this.hikApi.VideoService.StartDownloadFile(this.session.UserId, remoteFile.Name, destinationFilePath); this.logger.Info($"{remoteFile.ToUserFriendlyString()}- downloading"); this.currentDownloadFile = remoteFile; this.progress = this.config.ShowProgress ? this.progressFactory.Create() : default(IProgressBar); return(true); } this.logger.Info($"{remoteFile.ToUserFriendlyString()}- exist"); return(false); } else { this.logger.Warn("HikClient.StartDownload : Downloading, please stop firstly!"); return(false); } }