private FFMpegInfo GetExistingVersion(FFMpegInfo info, string rootEncoderPath)
        {
            var encoderFilename = Path.GetFileName(info.EncoderPath);
            var probeFilename = Path.GetFileName(info.ProbePath);

            foreach (var directory in Directory.EnumerateDirectories(rootEncoderPath, "*", SearchOption.TopDirectoryOnly)
                .ToList())
            {
                var allFiles = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories).ToList();

                var encoder = allFiles.FirstOrDefault(i => string.Equals(Path.GetFileName(i), encoderFilename, StringComparison.OrdinalIgnoreCase));
                var probe = allFiles.FirstOrDefault(i => string.Equals(Path.GetFileName(i), probeFilename, StringComparison.OrdinalIgnoreCase));

                if (!string.IsNullOrWhiteSpace(encoder) &&
                    !string.IsNullOrWhiteSpace(probe))
                {
                    return new FFMpegInfo
                    {
                         EncoderPath = encoder,
                         ProbePath = probe,
                         Version = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(probe))
                    };
                }
            }

            return null;
        }
        private FFMpegInfo GetExistingVersion(FFMpegInfo info, string rootEncoderPath)
        {
            var encoderFilename = Path.GetFileName(info.EncoderPath);
            var probeFilename = Path.GetFileName(info.ProbePath);

            foreach (var directory in Directory.EnumerateDirectories(rootEncoderPath, "*", SearchOption.TopDirectoryOnly)
                .ToList())
            {
                var allFiles = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories).ToList();

                var encoder = allFiles.FirstOrDefault(i => string.Equals(Path.GetFileName(i), encoderFilename, StringComparison.OrdinalIgnoreCase));
                var probe = allFiles.FirstOrDefault(i => string.Equals(Path.GetFileName(i), probeFilename, StringComparison.OrdinalIgnoreCase));

                if (!string.IsNullOrWhiteSpace(encoder) &&
                    !string.IsNullOrWhiteSpace(probe))
                {
                    return new FFMpegInfo
                    {
                         EncoderPath = encoder,
                         ProbePath = probe,
                         Version = Path.GetFileName(Path.GetDirectoryName(probe))
                    };
                }
            }

            return null;
        }
Exemple #3
0
        private async Task DownloadFFMpeg(FFMpegInfo info, IProgress <double> progress)
        {
            foreach (var url in FFMpegDownloadInfo.FfMpegUrls)
            {
                progress.Report(0);

                try
                {
                    var tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = CancellationToken.None,
                        Progress          = progress
                    }).ConfigureAwait(false);

                    ExtractFFMpeg(tempFile, Path.GetDirectoryName(info.Path));
                    return;
                }
                catch (HttpException ex)
                {
                    _logger.ErrorException("Error downloading {0}", ex, url);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error unpacking {0}", ex, url);
                }
            }

            throw new ApplicationException("Unable to download required components. Please try again later.");
        }
        public async Task<FFMpegInfo> GetFFMpegInfo()
        {
            var versionedDirectoryPath = Path.Combine(GetMediaToolsPath(true), FFMpegDownloadInfo.Version);

            var info = new FFMpegInfo
            {
                ProbePath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
                Path = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
                Version = FFMpegDownloadInfo.Version
            };

            Directory.CreateDirectory(versionedDirectoryPath);

            var tasks = new List<Task>();

            if (!File.Exists(info.ProbePath) || !File.Exists(info.Path))
            {
                tasks.Add(DownloadFFMpeg(info));
            }

            tasks.Add(DownloadFonts(versionedDirectoryPath));

            await Task.WhenAll(tasks).ConfigureAwait(false);

            return info;
        }
Exemple #5
0
        public async Task <FFMpegInfo> GetFFMpegInfo()
        {
            var versionedDirectoryPath = Path.Combine(GetMediaToolsPath(true), FFMpegDownloadInfo.Version);

            var info = new FFMpegInfo
            {
                ProbePath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
                Path      = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
                Version   = FFMpegDownloadInfo.Version
            };

            Directory.CreateDirectory(versionedDirectoryPath);

            var tasks = new List <Task>();

            if (!File.Exists(info.ProbePath) || !File.Exists(info.Path))
            {
                tasks.Add(DownloadFFMpeg(info));
            }

            tasks.Add(DownloadFonts(versionedDirectoryPath));

            await Task.WhenAll(tasks).ConfigureAwait(false);

            return(info);
        }
        public async Task<FFMpegInfo> GetFFMpegInfo(StartupOptions options, IProgress<double> progress)
        {
            var customffMpegPath = options.GetOption("-ffmpeg");
            var customffProbePath = options.GetOption("-ffprobe");

            if (!string.IsNullOrWhiteSpace(customffMpegPath) && !string.IsNullOrWhiteSpace(customffProbePath))
            {
                return new FFMpegInfo
                {
                    ProbePath = customffProbePath,
                    EncoderPath = customffMpegPath,
                    Version = "custom"
                };
            }

            var rootEncoderPath = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg");
            var versionedDirectoryPath = Path.Combine(rootEncoderPath, FFMpegDownloadInfo.Version);

            var info = new FFMpegInfo
            {
                ProbePath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
                EncoderPath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
                Version = FFMpegDownloadInfo.Version
            };

            Directory.CreateDirectory(versionedDirectoryPath);

            var excludeFromDeletions = new List<string> { versionedDirectoryPath };

            if (!File.Exists(info.ProbePath) || !File.Exists(info.EncoderPath))
            {
                // ffmpeg not present. See if there's an older version we can start with
                var existingVersion = GetExistingVersion(info, rootEncoderPath);

                // No older version. Need to download and block until complete
                if (existingVersion == null)
                {
                    await DownloadFFMpeg(versionedDirectoryPath, progress).ConfigureAwait(false);
                }
                else
                {
                    // Older version found. 
                    // Start with that. Download new version in the background.
                    var newPath = versionedDirectoryPath;
                    Task.Run(() => DownloadFFMpegInBackground(newPath));

                    info = existingVersion;
                    versionedDirectoryPath = Path.GetDirectoryName(info.EncoderPath);

                    excludeFromDeletions.Add(versionedDirectoryPath);
                }
            }

            await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false);

            DeleteOlderFolders(Path.GetDirectoryName(versionedDirectoryPath), excludeFromDeletions);

            return info;
        }
Exemple #7
0
        public async Task <FFMpegInfo> GetFFMpegInfo(IProgress <double> progress)
        {
            var versionedDirectoryPath = Path.Combine(GetMediaToolsPath(true), FFMpegDownloadInfo.Version);

            var info = new FFMpegInfo
            {
                ProbePath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
                Path      = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
                Version   = FFMpegDownloadInfo.Version
            };

            Directory.CreateDirectory(versionedDirectoryPath);

            var tasks = new List <Task>();

            double ffmpegPercent = 0;
            double fontPercent   = 0;
            var    syncLock      = new object();

            if (!File.Exists(info.ProbePath) || !File.Exists(info.Path))
            {
                var ffmpegProgress = new ActionableProgress <double>();
                ffmpegProgress.RegisterAction(p =>
                {
                    ffmpegPercent = p;

                    lock (syncLock)
                    {
                        progress.Report((ffmpegPercent / 2) + (fontPercent / 2));
                    }
                });

                tasks.Add(DownloadFFMpeg(info, ffmpegProgress));
            }
            else
            {
                ffmpegPercent = 100;
                progress.Report(50);
            }

            var fontProgress = new ActionableProgress <double>();

            fontProgress.RegisterAction(p =>
            {
                fontPercent = p;

                lock (syncLock)
                {
                    progress.Report((ffmpegPercent / 2) + (fontPercent / 2));
                }
            });

            tasks.Add(DownloadFonts(versionedDirectoryPath, fontProgress));

            await Task.WhenAll(tasks).ConfigureAwait(false);

            return(info);
        }
        public async Task<FFMpegInfo> GetFFMpegInfo(IProgress<double> progress)
        {
            var versionedDirectoryPath = Path.Combine(GetMediaToolsPath(true), FFMpegDownloadInfo.Version);

            var info = new FFMpegInfo
            {
                ProbePath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
                Path = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
                Version = FFMpegDownloadInfo.Version
            };

            Directory.CreateDirectory(versionedDirectoryPath);

            var tasks = new List<Task>();

            double ffmpegPercent = 0;
            double fontPercent = 0;
            var syncLock = new object();

            if (!File.Exists(info.ProbePath) || !File.Exists(info.Path))
            {
                var ffmpegProgress = new ActionableProgress<double>();
                ffmpegProgress.RegisterAction(p =>
                {
                    ffmpegPercent = p;

                    lock (syncLock)
                    {
                        progress.Report((ffmpegPercent / 2) + (fontPercent / 2));
                    }
                });

                tasks.Add(DownloadFFMpeg(info, ffmpegProgress));
            }
            else
            {
                ffmpegPercent = 100;
                progress.Report(50);
            }

            var fontProgress = new ActionableProgress<double>();
            fontProgress.RegisterAction(p =>
            {
                fontPercent = p;

                lock (syncLock)
                {
                    progress.Report((ffmpegPercent / 2) + (fontPercent / 2));
                }
            });

            tasks.Add(DownloadFonts(versionedDirectoryPath, fontProgress));

            await Task.WhenAll(tasks).ConfigureAwait(false);

            return info;
        }
Exemple #9
0
        private Task <string> DownloadFFMpeg(FFMpegInfo info, string url)
        {
            return(_httpClient.GetTempFile(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = CancellationToken.None,
                Progress = new Progress <double>(),

                // Make it look like a browser
                // Try to hide that we're direct linking
                UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.47 Safari/537.36"
            }));
        }
Exemple #10
0
        private async Task DownloadFFMpeg(FFMpegInfo info)
        {
            foreach (var url in FFMpegDownloadInfo.FfMpegUrls)
            {
                try
                {
                    var tempFile = await DownloadFFMpeg(info, url).ConfigureAwait(false);

                    ExtractFFMpeg(tempFile, Path.GetDirectoryName(info.Path));
                    return;
                }
                catch (HttpException ex)
                {
                }
            }

            throw new ApplicationException("Unable to download required components. Please try again later.");
        }
        private async Task DownloadFFMpeg(FFMpegInfo info)
        {
            foreach (var url in FFMpegDownloadInfo.FfMpegUrls)
            {
                try
                {
                    var tempFile = await DownloadFFMpeg(info, url).ConfigureAwait(false);

                    ExtractFFMpeg(tempFile, Path.GetDirectoryName(info.Path));
                    return;
                }
                catch (HttpException ex)
                {

                }
            }

            throw new ApplicationException("Unable to download required components. Please try again later.");
        }
        public async Task<FFMpegInfo> GetFFMpegInfo(IProgress<double> progress)
        {
            var rootEncoderPath = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg");
            var versionedDirectoryPath = Path.Combine(rootEncoderPath, FFMpegDownloadInfo.Version);

            var info = new FFMpegInfo
            {
                ProbePath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
                EncoderPath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
                Version = FFMpegDownloadInfo.Version
            };

            Directory.CreateDirectory(versionedDirectoryPath);

            if (!File.Exists(info.ProbePath) || !File.Exists(info.EncoderPath))
            {
                // ffmpeg not present. See if there's an older version we can start with
                var existingVersion = GetExistingVersion(info, rootEncoderPath);

                // No older version. Need to download and block until complete
                if (existingVersion == null)
                {
                    await DownloadFFMpeg(versionedDirectoryPath, progress).ConfigureAwait(false);
                }
                else
                {
                    // Older version found. 
                    // Start with that. Download new version in the background.
                    var newPath = versionedDirectoryPath;
                    Task.Run(() => DownloadFFMpegInBackground(newPath));

                    info = existingVersion;
                    versionedDirectoryPath = Path.GetDirectoryName(info.EncoderPath);
                }
            }

            await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false);

            return info;
        }
        public async Task<FFMpegInfo> GetFFMpegInfo(IProgress<double> progress)
        {
            var rootEncoderPath = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg");
            var versionedDirectoryPath = Path.Combine(rootEncoderPath, FFMpegDownloadInfo.Version);

            var info = new FFMpegInfo
            {
                ProbePath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
                EncoderPath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
                Version = FFMpegDownloadInfo.Version
            };

            Directory.CreateDirectory(versionedDirectoryPath);

            if (!File.Exists(info.ProbePath) || !File.Exists(info.EncoderPath))
            {
                // ffmpeg not present. See if there's an older version we can start with
                var existingVersion = GetExistingVersion(info, rootEncoderPath);

                // No older version. Need to download and block until complete
                if (existingVersion == null)
                {
                    await DownloadFFMpeg(versionedDirectoryPath, progress).ConfigureAwait(false);
                }
                else
                {
                    // Older version found. 
                    // Start with that. Download new version in the background.
                    var newPath = versionedDirectoryPath;
                    Task.Run(() => DownloadFFMpegInBackground(newPath));

                    info = existingVersion;
                    versionedDirectoryPath = Path.GetDirectoryName(info.EncoderPath);
                }
            }

            await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false);

            return info;
        }
Exemple #14
0
        public async Task <FFMpegInfo> GetFFMpegInfo(StartupOptions options, IProgress <double> progress)
        {
            var customffMpegPath  = options.GetOption("-ffmpeg");
            var customffProbePath = options.GetOption("-ffprobe");

            if (!string.IsNullOrWhiteSpace(customffMpegPath) && !string.IsNullOrWhiteSpace(customffProbePath))
            {
                return(new FFMpegInfo
                {
                    ProbePath = customffProbePath,
                    EncoderPath = customffMpegPath,
                    Version = "custom"
                });
            }

            var rootEncoderPath        = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg");
            var versionedDirectoryPath = Path.Combine(rootEncoderPath, FFMpegDownloadInfo.Version);

            var info = new FFMpegInfo
            {
                ProbePath   = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
                EncoderPath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
                Version     = FFMpegDownloadInfo.Version
            };

            Directory.CreateDirectory(versionedDirectoryPath);

            var excludeFromDeletions = new List <string> {
                versionedDirectoryPath
            };

            if (!File.Exists(info.ProbePath) || !File.Exists(info.EncoderPath))
            {
                // ffmpeg not present. See if there's an older version we can start with
                var existingVersion = GetExistingVersion(info, rootEncoderPath);

                // No older version. Need to download and block until complete
                if (existingVersion == null)
                {
                    await DownloadFFMpeg(versionedDirectoryPath, progress).ConfigureAwait(false);
                }
                else
                {
                    // Older version found.
                    // Start with that. Download new version in the background.
                    var newPath = versionedDirectoryPath;
                    Task.Run(() => DownloadFFMpegInBackground(newPath));

                    info = existingVersion;
                    versionedDirectoryPath = Path.GetDirectoryName(info.EncoderPath);

                    excludeFromDeletions.Add(versionedDirectoryPath);
                }
            }

            await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false);

            DeleteOlderFolders(Path.GetDirectoryName(versionedDirectoryPath), excludeFromDeletions);

            return(info);
        }
        private Task<string> DownloadFFMpeg(FFMpegInfo info, string url)
        {
            return _httpClient.GetTempFile(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = CancellationToken.None,
                Progress = new Progress<double>(),

                // Make it look like a browser
                // Try to hide that we're direct linking
                UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.47 Safari/537.36"
            });
        }
        private async Task DownloadFFMpeg(FFMpegInfo info, IProgress<double> progress)
        {
            foreach (var url in FFMpegDownloadInfo.FfMpegUrls)
            {
                progress.Report(0);

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

                    }).ConfigureAwait(false);

                    ExtractFFMpeg(tempFile, Path.GetDirectoryName(info.Path));
                    return;
                }
                catch (HttpException ex)
                {
                    _logger.ErrorException("Error downloading {0}", ex, url);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error unpacking {0}", ex, url);
                }
            }

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