72 lines
2.4 KiB
PowerShell
72 lines
2.4 KiB
PowerShell
param(
|
|
[string]$Url = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip",
|
|
[string]$OutDir = "tools/ffmpeg/bin",
|
|
[switch]$DryRun
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$isWindows = $env:OS -eq 'Windows_NT'
|
|
if (-not $isWindows) {
|
|
Write-Host "This script is intended for Windows (ffmpeg.exe)." -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
|
|
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
|
$outDirAbs = (Resolve-Path (Join-Path $repoRoot $OutDir) -ErrorAction SilentlyContinue)
|
|
if (-not $outDirAbs) {
|
|
$outDirAbs = Join-Path $repoRoot $OutDir
|
|
New-Item -ItemType Directory -Force -Path $outDirAbs | Out-Null
|
|
} else {
|
|
$outDirAbs = $outDirAbs.Path
|
|
}
|
|
|
|
$ffmpegDest = Join-Path $outDirAbs "ffmpeg.exe"
|
|
|
|
# If already present, do nothing.
|
|
if (Test-Path $ffmpegDest) {
|
|
Write-Host "FFmpeg already present: $ffmpegDest"
|
|
exit 0
|
|
}
|
|
|
|
if ($DryRun) {
|
|
Write-Host "Dry run:" -ForegroundColor Cyan
|
|
Write-Host " Would download: $Url"
|
|
Write-Host " Would install to: $ffmpegDest"
|
|
exit 0
|
|
}
|
|
|
|
Write-Host "About to download a prebuilt FFmpeg package:" -ForegroundColor Cyan
|
|
Write-Host " $Url"
|
|
Write-Host "You are responsible for reviewing the FFmpeg license/compliance for your use case." -ForegroundColor Yellow
|
|
|
|
$tempRoot = Join-Path $env:TEMP ("radioplayer-ffmpeg-" + [guid]::NewGuid().ToString("N"))
|
|
$zipPath = Join-Path $tempRoot "ffmpeg.zip"
|
|
$extractDir = Join-Path $tempRoot "extract"
|
|
|
|
New-Item -ItemType Directory -Force -Path $tempRoot | Out-Null
|
|
New-Item -ItemType Directory -Force -Path $extractDir | Out-Null
|
|
|
|
try {
|
|
Write-Host "Downloading..." -ForegroundColor Cyan
|
|
Invoke-WebRequest -Uri $Url -OutFile $zipPath -UseBasicParsing
|
|
|
|
Write-Host "Extracting..." -ForegroundColor Cyan
|
|
Expand-Archive -Path $zipPath -DestinationPath $extractDir -Force
|
|
|
|
$candidate = Get-ChildItem -Path $extractDir -Recurse -Filter "ffmpeg.exe" | Where-Object {
|
|
$_.FullName -match "\\bin\\ffmpeg\.exe$"
|
|
} | Select-Object -First 1
|
|
|
|
if (-not $candidate) {
|
|
throw "Could not find ffmpeg.exe under extracted content. The archive layout may have changed."
|
|
}
|
|
|
|
Copy-Item -Force -Path $candidate.FullName -Destination $ffmpegDest
|
|
|
|
Write-Host "Installed FFmpeg to: $ffmpegDest" -ForegroundColor Green
|
|
Write-Host "Next: run 'node tools/copy-ffmpeg.js' (or 'npm run dev:native' / 'npm run build') to bundle it into src-tauri/resources/." -ForegroundColor Green
|
|
} finally {
|
|
try { Remove-Item -Recurse -Force -Path $tempRoot -ErrorAction SilentlyContinue } catch {}
|
|
}
|