Files
MeBox/scripts/install-ffmpeg.ps1
T
ShukeBta 5d1ae91419 feat: 站点适配器 FlareSolverr 集成 + 并发搜索优化
- site_adapter.go: SiteConfig 扩展 UserAgent/Timeout/Extra/FlareSolverrURL 字段
- site_adapter.go: doRequest() GET 请求支持 FlareSolverr 代理绕过 Cloudflare/WAF
- site_adapter.go: buildRequest() 使用 cfg.UserAgent(覆盖默认 UA)
- site_adapter.go: MTeam api_key 认证改为 Authorization: Bearer 格式
- site_adapter.go: 修复 2 个 go vet 冗余 StatusFound 警告
- site.go: Search() 重构为 sync.WaitGroup 并发执行,提升多站搜索性能
- site.go: siteModelToConfig() 改为 SiteService 方法,按 BrowserEmulation 填充 FlareSolverrURL
- site.go: Search() 空关键词返回 [] 而非 error,nil slice 防护
- 新增 system_handler.go: 系统工具探测接口
- 新增 ffmpeg_auto_install.go: FFmpeg 自动安装服务
- 新增 scripts/install-ffmpeg.ps1: Windows FFmpeg 安装脚本
2026-05-24 17:14:47 +08:00

149 lines
5.2 KiB
PowerShell

# Windows 自动安装 ffmpeg/ffprobe 脚本
# 在项目首次运行或用户手动点击工具页按钮时执行。
param(
[string]$InstallDir = (Join-Path $PSScriptRoot "..\tools\ffmpeg"),
[string]$ConfigFile = (Join-Path $PSScriptRoot "..\config.yaml")
)
$ErrorActionPreference = "Stop"
$previousProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
$tempRoot = $null
function Test-ToolInstalled {
param([string]$BaseDir)
$ffmpeg = Join-Path $BaseDir "bin\ffmpeg.exe"
$ffprobe = Join-Path $BaseDir "bin\ffprobe.exe"
return (Test-Path $ffmpeg) -and (Test-Path $ffprobe)
}
function Update-ConfigFile {
param(
[string]$Path,
[string]$FFmpegPath,
[string]$FFprobePath
)
if (!(Test-Path $Path)) {
return
}
$content = Get-Content -Path $Path
$content = $content | ForEach-Object {
if ($_ -match '^\s*ffmpeg_path:') {
" ffmpeg_path: $FFmpegPath"
} elseif ($_ -match '^\s*ffprobe_path:') {
" ffprobe_path: $FFprobePath"
} else {
$_
}
}
Set-Content -Path $Path -Value $content -Encoding UTF8
}
function Cleanup-Temp {
if ($tempRoot -and (Test-Path $tempRoot)) {
Remove-Item -LiteralPath $tempRoot -Recurse -Force
}
}
Write-Host "=== MediaStationGo ffmpeg 自动安装脚本 ===" -ForegroundColor Cyan
Write-Host ""
$InstallDir = [System.IO.Path]::GetFullPath($InstallDir)
$ConfigFile = [System.IO.Path]::GetFullPath($ConfigFile)
$ffmpegPath = Join-Path $InstallDir "bin\ffmpeg.exe"
$ffprobePath = Join-Path $InstallDir "bin\ffprobe.exe"
$arch = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" }
Write-Host "检测到系统架构: $arch" -ForegroundColor Yellow
Write-Host "安装目录: $InstallDir" -ForegroundColor Yellow
trap {
Write-Host "✗ 自动安装失败: $($_.Exception.Message)" -ForegroundColor Red
if ($_.InvocationInfo) {
Write-Host ("行 {0}: {1}" -f $_.InvocationInfo.ScriptLineNumber, $_.InvocationInfo.Line.Trim()) -ForegroundColor DarkRed
}
Write-Host ""
Write-Host "请手动下载安装并放到以下目录:" -ForegroundColor Yellow
Write-Host $InstallDir -ForegroundColor Yellow
$ProgressPreference = $previousProgressPreference
Cleanup-Temp
exit 1
}
if (Test-ToolInstalled -BaseDir $InstallDir) {
Write-Host "✓ ffmpeg 已安装" -ForegroundColor Green
& $ffprobePath -version | Select-Object -First 1
exit 0
}
$downloadUrls = @(
"https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip",
"https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-$arch-gpl.zip"
)
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
$tempRoot = Join-Path $env:TEMP ("mediastationgo-ffmpeg-" + [guid]::NewGuid().ToString("N"))
$zipFile = Join-Path $tempRoot "ffmpeg.zip"
$extractDir = Join-Path $tempRoot "extract"
New-Item -ItemType Directory -Path $extractDir -Force | Out-Null
$downloaded = $false
foreach ($downloadUrl in $downloadUrls) {
try {
Write-Host "下载 ffmpeg..." -ForegroundColor Yellow
Write-Host "URL: $downloadUrl"
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipFile
$downloaded = $true
break
} catch {
Write-Host "下载失败,尝试备用地址: $downloadUrl" -ForegroundColor DarkYellow
}
}
if (-not $downloaded) {
throw "所有下载地址均不可用"
}
Write-Host "解压文件..." -ForegroundColor Yellow
Expand-Archive -Path $zipFile -DestinationPath $extractDir -Force
$ffmpegBinaryPath = "" + (Get-ChildItem -Path $extractDir -Recurse -Filter "ffmpeg.exe" -File |
Select-Object -First 1 -ExpandProperty FullName)
$ffprobeBinaryPath = "" + (Get-ChildItem -Path $extractDir -Recurse -Filter "ffprobe.exe" -File |
Select-Object -First 1 -ExpandProperty FullName)
if ([string]::IsNullOrWhiteSpace($ffmpegBinaryPath) -or [string]::IsNullOrWhiteSpace($ffprobeBinaryPath)) {
Write-Host "未找到预期二进制,解压结果样本:" -ForegroundColor DarkYellow
Get-ChildItem -Path $extractDir -Recurse -File | Select-Object -First 20 FullName | ForEach-Object {
Write-Host $_.FullName -ForegroundColor DarkYellow
}
throw "解压后未找到包含 bin\ffmpeg.exe 的目录"
}
$packageRoot = Split-Path -Parent (Split-Path -Parent $ffmpegBinaryPath)
Copy-Item -Path (Join-Path $packageRoot "*") -Destination $InstallDir -Recurse -Force
if (-not (Test-ToolInstalled -BaseDir $InstallDir)) {
throw "ffmpeg 文件未正确安装到 $InstallDir\bin"
}
$env:PATH = "$InstallDir\bin;$env:PATH"
Update-ConfigFile -Path $ConfigFile -FFmpegPath $ffmpegPath -FFprobePath $ffprobePath
Write-Host "✓ 安装完成" -ForegroundColor Green
Write-Host "ffmpeg: $ffmpegPath" -ForegroundColor Green
Write-Host "ffprobe: $ffprobePath" -ForegroundColor Green
& $ffprobePath -version | Select-Object -First 1
$ProgressPreference = $previousProgressPreference
Cleanup-Temp
Write-Host ""
Write-Host "提示: 如需永久加入 PATH,请以管理员执行:" -ForegroundColor Cyan
Write-Host "[Environment]::SetEnvironmentVariable('PATH', `$env:PATH + ';$InstallDir\bin', 'Machine')" -ForegroundColor Gray