示例#1
0
        private void ExtractArchive(FFMpegDownloadInfo downloadinfo, string archivePath, string targetPath)
        {
            _logger.Info("Extracting {0} to {1}", archivePath, targetPath);

            if (string.Equals(downloadinfo.ArchiveType, "7z", StringComparison.OrdinalIgnoreCase))
            {
                _zipClient.ExtractAllFrom7z(archivePath, targetPath, true);
            }
            else if (string.Equals(downloadinfo.ArchiveType, "gz", StringComparison.OrdinalIgnoreCase))
            {
                _zipClient.ExtractAllFromTar(archivePath, targetPath, true);
            }
        }
示例#2
0
        private void ExtractFFMpeg(FFMpegDownloadInfo downloadinfo, string tempFile, string targetFolder)
        {
            _logger.Info("Extracting ffmpeg from {0}", tempFile);

            var tempFolder = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString());

			_fileSystem.CreateDirectory(tempFolder);

            try
            {
                ExtractArchive(downloadinfo, tempFile, tempFolder);

                var files = Directory.EnumerateFiles(tempFolder, "*", SearchOption.AllDirectories)
                    .ToList();

                foreach (var file in files.Where(i =>
                    {
                        var filename = Path.GetFileName(i);

                        return
                            string.Equals(filename, downloadinfo.FFProbeFilename, StringComparison.OrdinalIgnoreCase) ||
                            string.Equals(filename, downloadinfo.FFMpegFilename, StringComparison.OrdinalIgnoreCase);
                    }))
                {
                    var targetFile = Path.Combine(targetFolder, Path.GetFileName(file));
					_fileSystem.CopyFile(file, targetFile, true);
                    SetFilePermissions(targetFile);
                }
            }
            finally
            {
                DeleteFile(tempFile);
            }
        }
示例#3
0
 private async void DownloadFFMpegInBackground(FFMpegDownloadInfo downloadinfo, string directory)
 {
     try
     {
         await DownloadFFMpeg(downloadinfo, directory, new Progress<double>()).ConfigureAwait(false);
     }
     catch (Exception ex)
     {
         _logger.ErrorException("Error downloading ffmpeg", ex);
     }
 }
示例#4
0
        private async Task DownloadFFMpeg(FFMpegDownloadInfo downloadinfo, string directory, IProgress<double> progress)
        {
            foreach (var url in downloadinfo.DownloadUrls)
            {
                progress.Report(0);

                try
                {
                    var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = CancellationToken.None,
                        Progress = progress

                    }).ConfigureAwait(false);

                    ExtractFFMpeg(downloadinfo, tempFile, directory);
                    return;
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error downloading {0}", ex, url);
                }
            }

            if (downloadinfo.DownloadUrls.Length == 0)
            {
                throw new ApplicationException("ffmpeg unvailable. Please install it and start the server with two command line arguments: -ffmpeg \"{PATH}\" and -ffprobe \"{PATH}\"");
            }
            else
            {
                throw new ApplicationException("Unable to download required components. Please try again later.");
            }
        }
示例#5
0
        private async Task DownloadFFMpeg(FFMpegDownloadInfo downloadinfo, string directory, IProgress<double> progress)
        {
            foreach (var url in downloadinfo.DownloadUrls)
            {
                progress.Report(0);

                try
                {
                    var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = CancellationToken.None,
                        Progress = progress

                    }).ConfigureAwait(false);

                    ExtractFFMpeg(downloadinfo, tempFile, directory);
                    return;
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error downloading {0}", ex, url);
                }
            }

            throw new ApplicationException("Unable to download required components. Please try again later.");
        }