Download FFmpeg via a project target

This commit is contained in:
Tyrrrz 2025-05-11 02:05:00 +03:00
parent 1041df0007
commit 6dbfd290fa
4 changed files with 78 additions and 66 deletions

View File

@ -92,16 +92,12 @@ jobs:
with:
dotnet-version: 9.0.x
- name: Download FFmpeg
if: ${{ matrix.bundle-ffmpeg }}
shell: pwsh
run: YoutubeDownloader/DownloadFFmpeg.ps1 -platform ${{ matrix.rid }}
- name: Publish app
run: >
dotnet publish YoutubeDownloader
-p:Version=${{ github.ref_type == 'tag' && github.ref_name || format('999.9.9-ci-{0}', github.sha) }}
-p:CSharpier_Bypass=true
-p:DownloadFFmpeg=${{ matrix.bundle-ffmpeg }}
--output YoutubeDownloader/bin/publish
--configuration Release
--runtime ${{ matrix.rid }}

View File

@ -0,0 +1,68 @@
param (
[Parameter(Mandatory=$false)]
[string]$Platform,
[Parameter(Mandatory=$false)]
[string]$OutputPath
)
$ErrorActionPreference = "Stop"
# If the platform is not specified, use the current OS/arch
if (-not $Platform) {
$arch = [Runtime.InteropServices.RuntimeInformation]::OSArchitecture
if ($isWindows) {
$Platform = "windows-$arch"
} elseif ($isLinux) {
$Platform = "linux-$arch"
} elseif ($isMacOS) {
$Platform = "osx-$arch"
} else {
throw "Unsupported platform"
}
}
# Normalize platform identifier
$Platform = $Platform.ToLower().Replace("win-", "windows-")
$fileName = if ($Platform.Contains("windows-")) { "ffmpeg.exe" } else { "ffmpeg" }
# If the output path is not specified, use the current directory
if (-not $OutputPath) {
$OutputPath = "$PSScriptRoot/$fileName"
}
# If the output path is an existing directory, append the default file name for the platform
if (Test-Path $OutputPath -PathType Container) {
$OutputPath = Join-Path $OutputPath $fileName
}
# Delete the existing file if it exists
if (Test-Path $OutputPath) {
Remove-Item $OutputPath
}
# Download the archive
Write-Host "Downloading FFmpeg for $Platform..."
$http = New-Object System.Net.WebClient
try {
$http.DownloadFile("https://github.com/Tyrrrz/FFmpegBin/releases/download/7.0/ffmpeg-$Platform.zip", "$OutputPath.zip")
} finally {
$http.Dispose()
}
try {
# Extract FFmpeg
Add-Type -Assembly System.IO.Compression.FileSystem
$zip = [IO.Compression.ZipFile]::OpenRead("$OutputPath.zip")
try {
[IO.Compression.ZipFileExtensions]::ExtractToFile($zip.GetEntry($fileName), $OutputPath)
} finally {
$zip.Dispose()
}
Write-Host "Done downloading FFmpeg."
} finally {
# Clean up
Remove-Item "$OutputPath.zip" -Force
}

View File

@ -1,61 +0,0 @@
param (
[string]$platform,
[string]$outputPath
)
$ErrorActionPreference = "Stop"
# If the platform is not specified, use the current OS/arch
if (-not $platform) {
$arch = [Runtime.InteropServices.RuntimeInformation]::OSArchitecture
if ($isWindows) {
$platform = "windows-$arch"
} elseif ($isLinux) {
$platform = "linux-$arch"
} elseif ($isMacOS) {
$platform = "osx-$arch"
} else {
throw "Unsupported platform"
}
}
# Normalize platform identifier
$platform = $platform.ToLower().Replace("win-", "windows-")
# If the output path is not specified, use the current directory
if (-not $outputPath) {
$fileName = if ($platform.Contains("windows-")) { "ffmpeg.exe" } else { "ffmpeg" }
$outputPath = "$PSScriptRoot/$fileName"
}
# Delete the existing file if it exists
if (Test-Path $outputPath) {
Remove-Item $outputPath
}
# Download the archive
Write-Host "Downloading FFmpeg for $platform..."
$http = New-Object System.Net.WebClient
try {
$http.DownloadFile("https://github.com/Tyrrrz/FFmpegBin/releases/download/7.0/ffmpeg-$platform.zip", "$outputPath.zip")
} finally {
$http.Dispose()
}
try {
# Extract FFmpeg
Add-Type -Assembly System.IO.Compression.FileSystem
$zip = [IO.Compression.ZipFile]::OpenRead("$outputPath.zip")
try {
$fileName = If ($platform.Contains("windows-")) { "ffmpeg.exe" } Else { "ffmpeg" }
[IO.Compression.ZipFileExtensions]::ExtractToFile($zip.GetEntry($fileName), $outputPath)
} finally {
$zip.Dispose()
}
Write-Host "Done downloading FFmpeg."
} finally {
# Clean up
Remove-Item "$outputPath.zip" -Force
}

View File

@ -12,6 +12,10 @@
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<PropertyGroup>
<DownloadFFmpeg>true</DownloadFFmpeg>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="..\favicon.ico" Link="favicon.ico" />
</ItemGroup>
@ -60,4 +64,9 @@
<TrimmerRootAssembly Include="WebView.Core" />
</ItemGroup>
<Target Name="DownloadFFmpeg" BeforeTargets="Restore;PreBuildEvent" Condition="$(DownloadFFmpeg) AND !Exists('ffmpeg.exe') AND !Exists('ffmpeg')">
<Exec Command="pwsh -ExecutionPolicy Bypass -File $(ProjectDir)/Download-FFmpeg.ps1 -Platform $(RuntimeIdentifier) -OutputPath $(ProjectDir)" LogStandardErrorAsError="true" Condition="'$(RuntimeIdentifier)' != ''" />
<Exec Command="pwsh -ExecutionPolicy Bypass -File $(ProjectDir)/Download-FFmpeg.ps1 -OutputPath $(ProjectDir)" LogStandardErrorAsError="true" Condition="'$(RuntimeIdentifier)' == ''" />
</Target>
</Project>