FFMpegCore/FFMpegCore.Extensions.Downloader/FFMpegDownloader.cs

54 lines
2.5 KiB
C#
Raw Normal View History

2025-01-27 22:22:47 -05:00
using FFMpegCore.Extensions.Downloader.Enums;
using FFMpegCore.Extensions.Downloader.Exceptions;
using FFMpegCore.Extensions.Downloader.Services;
namespace FFMpegCore.Extensions.Downloader;
public class FFMpegDownloader
{
/// <summary>
/// Download the latest FFMpeg suite binaries for current platform
/// </summary>
/// <param name="version">used to explicitly state the version of binary you want to download</param>
2023-09-06 13:19:02 -06:00
/// <param name="binaries">used to explicitly state the binaries you want to download (ffmpeg, ffprobe, ffplay)</param>
/// <param name="platformOverride">used to explicitly state the os and architecture you want to download</param>
/// <returns>a list of the binaries that have been successfully downloaded</returns>
2023-09-06 13:19:02 -06:00
public static async Task<List<string>> DownloadFFMpegSuite(
FFMpegVersions version = FFMpegVersions.Latest,
FFMpegBinaries binaries = FFMpegBinaries.FFMpeg | FFMpegBinaries.FFProbe,
2025-01-27 22:22:47 -05:00
SupportedPlatforms? platformOverride = null)
{
2025-01-27 22:22:47 -05:00
// get all available versions
var versionInfo = await FFbinariesService.GetVersionInfo(version);
2025-01-27 22:30:22 -05:00
2025-01-27 22:22:47 -05:00
// get the download info for the current platform
2023-09-06 13:19:02 -06:00
var downloadInfo = versionInfo.BinaryInfo?.GetCompatibleDownloadInfo(platformOverride) ??
throw new FFMpegDownloaderException("Failed to get compatible download info");
2025-01-27 22:30:22 -05:00
var successList = new List<string>();
2025-01-27 22:30:22 -05:00
2025-01-27 22:22:47 -05:00
// download ffmpeg if selected
if (binaries.HasFlag(FFMpegBinaries.FFMpeg) && downloadInfo.FFMpeg is not null)
{
await using var zipStream = await FFbinariesService.DownloadFileAsSteam(new Uri(downloadInfo.FFMpeg));
2025-01-27 22:22:47 -05:00
successList.AddRange(FFbinariesService.ExtractZipAndSave(zipStream));
}
2025-01-27 22:22:47 -05:00
// download ffprobe if selected
if (binaries.HasFlag(FFMpegBinaries.FFProbe) && downloadInfo.FFProbe is not null)
{
await using var zipStream = await FFbinariesService.DownloadFileAsSteam(new Uri(downloadInfo.FFProbe));
2025-01-27 22:22:47 -05:00
successList.AddRange(FFbinariesService.ExtractZipAndSave(zipStream));
}
2025-01-27 22:22:47 -05:00
// download ffplay if selected
if (binaries.HasFlag(FFMpegBinaries.FFPlay) && downloadInfo.FFPlay is not null)
{
await using var zipStream = await FFbinariesService.DownloadFileAsSteam(new Uri(downloadInfo.FFPlay));
2025-01-27 22:22:47 -05:00
successList.AddRange(FFbinariesService.ExtractZipAndSave(zipStream));
}
return successList;
}
}