@@ -67,21 +67,76 @@ jobs:
6767 run : |
6868 Write-Host "Downloading ffmpeg for Windows"
6969
70- # Download ffmpeg to temp directory
71- $tempDir = New-Item -ItemType Directory -Path (Join-Path $env:TEMP "ffmpeg-temp-$(Get-Random)")
72- $url = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip"
73- $zipPath = Join-Path $tempDir "ffmpeg.zip"
74- Invoke-WebRequest -Uri $url -OutFile $zipPath
75-
76- # Extract to temp directory
77- Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
78-
79- # Find and move ffmpeg.exe
80- $ffmpegDir = Get-ChildItem -Path $tempDir -Directory -Filter "ffmpeg-*" | Select-Object -First 1
81- Move-Item -Path (Join-Path $ffmpegDir.FullName "bin/ffmpeg.exe") -Destination lib/win/ffmpeg.exe -Force
70+ # Function to download and extract ffmpeg with timeout
71+ function Install-Ffmpeg {
72+ param([int]$TimeoutSeconds = 60)
73+
74+ $tempDir = New-Item -ItemType Directory -Path (Join-Path $env:TEMP "ffmpeg-temp-$(Get-Random)")
75+ $url = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip"
76+ $zipPath = Join-Path $tempDir "ffmpeg.zip"
77+
78+ try {
79+ # Download with timeout
80+ $job = Start-Job -ScriptBlock {
81+ param($url, $zipPath)
82+ Invoke-WebRequest -Uri $url -OutFile $zipPath
83+ } -ArgumentList $url, $zipPath
84+
85+ if (Wait-Job -Job $job -Timeout $TimeoutSeconds) {
86+ Receive-Job -Job $job
87+ Remove-Job -Job $job -Force
88+
89+ # Extract with timeout
90+ $extractJob = Start-Job -ScriptBlock {
91+ param($zipPath, $tempDir)
92+ Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
93+ } -ArgumentList $zipPath, $tempDir
94+
95+ if (Wait-Job -Job $extractJob -Timeout $TimeoutSeconds) {
96+ Receive-Job -Job $extractJob
97+ Remove-Job -Job $extractJob -Force
98+
99+ # Find and move ffmpeg.exe
100+ $ffmpegDir = Get-ChildItem -Path $tempDir -Directory -Filter "ffmpeg-*" | Select-Object -First 1
101+ Move-Item -Path (Join-Path $ffmpegDir.FullName "bin/ffmpeg.exe") -Destination lib/win/ffmpeg.exe -Force
102+ return $true
103+ } else {
104+ Stop-Job -Job $extractJob
105+ Remove-Job -Job $extractJob -Force
106+ return $false
107+ }
108+ } else {
109+ Stop-Job -Job $job
110+ Remove-Job -Job $job -Force
111+ return $false
112+ }
113+ } finally {
114+ # Cleanup temp directory
115+ if (Test-Path $tempDir) {
116+ Remove-Item -Recurse -Force $tempDir -ErrorAction SilentlyContinue
117+ }
118+ }
119+ }
82120
83- # Cleanup temp directory
84- Remove-Item -Recurse -Force $tempDir
121+ # Try first attempt
122+ Write-Host "Attempting to download ffmpeg (attempt 1)..."
123+ if (Install-Ffmpeg -TimeoutSeconds 60) {
124+ Write-Host "ffmpeg installed successfully on first attempt"
125+ } else {
126+ Write-Host "First attempt failed or timed out, retrying..."
127+ # Clean up any stale temp directories (Install-Ffmpeg cleans up its own temp dir in finally block)
128+ Get-ChildItem -Path $env:TEMP -Directory -Filter "ffmpeg-temp-*" -ErrorAction SilentlyContinue |
129+ Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
130+
131+ # Retry
132+ Write-Host "Attempting to download ffmpeg (attempt 2)..."
133+ if (Install-Ffmpeg -TimeoutSeconds 60) {
134+ Write-Host "ffmpeg installed successfully on second attempt"
135+ } else {
136+ Write-Host "ffmpeg installation failed after 2 attempts"
137+ exit 1
138+ }
139+ }
85140
86141 # Verify
87142 lib/win/ffmpeg.exe -version
@@ -171,28 +226,7 @@ jobs:
171226 }
172227
173228 - name : Download ffmpeg for macOS
174- run : |
175- echo "Downloading ffmpeg for macOS"
176-
177- # Create temp directory for extraction
178- TEMP_DIR=$(mktemp -d)
179- cd "$TEMP_DIR"
180-
181- # Download ffmpeg static build for macOS
182- wget -q "https://evermeet.cx/ffmpeg/getrelease/ffmpeg/zip" -O ffmpeg.zip
183- unzip -q ffmpeg.zip
184-
185- # Move binary to lib/mac
186- chmod +x ffmpeg
187- mv ffmpeg "$GITHUB_WORKSPACE/lib/mac/ffmpeg"
188-
189- # Cleanup temp directory - change permissions first to ensure deletion succeeds
190- cd "$GITHUB_WORKSPACE"
191- chmod -R u+w "$TEMP_DIR" || true
192- rm -rf "$TEMP_DIR"
193-
194- # Verify
195- lib/mac/ffmpeg -version
229+ run : .github/scripts/install-ffmpeg-macos.sh lib/mac
196230
197231 - name : Build macOS executable with PyInstaller
198232 run : |
0 commit comments