[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [string]$Csv ) $ErrorActionPreference = 'Stop' $ffmpeg = Get-Command ffmpeg -ErrorAction SilentlyContinue if (-not $ffmpeg) { throw 'ffmpeg не найден. Установите FFmpeg через winget.' } $resolved = Resolve-Path -LiteralPath $Path -ErrorAction Stop $extensions = @('.mp3', '.wav', '.flac', '.ogg', '.m4a', '.aac', '.wma', '.opus') if (Test-Path -LiteralPath $resolved.Path -PathType Container) { $files = @(Get-ChildItem -LiteralPath $resolved.Path -File -Recurse -ErrorAction SilentlyContinue | Where-Object { $extensions -contains $_.Extension.ToLowerInvariant() }) } else { $item = Get-Item -LiteralPath $resolved.Path if ($extensions -notcontains $item.Extension.ToLowerInvariant()) { throw "Формат не похож на аудио: $($item.Extension)" } $files = @($item) } if ($files.Count -eq 0) { Write-Host 'Аудиофайлы не найдены.' exit 0 } $results = @() $bad = 0 foreach ($file in $files) { $output = & $ffmpeg.Source -hide_banner -v error -xerror -nostdin -i $file.FullName -f null - 2>&1 $ok = ($LASTEXITCODE -eq 0) if ($ok) { Write-Host "OK: $($file.FullName)" $status = 'OK' $errorText = '' } else { Write-Host "Ошибка: $($file.FullName)" -ForegroundColor Red $status = 'Ошибка' $errorText = ($output -join ' ').Trim() if ($errorText) { Write-Host $errorText -ForegroundColor DarkYellow } $bad++ } $results += [pscustomobject]@{ File = $file.FullName SizeMB = [math]::Round($file.Length / 1MB, 2) Status = $status Error = $errorText } } $results | Format-Table -AutoSize if ($Csv) { $csvPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Csv) $results | Export-Csv -LiteralPath $csvPath -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $csvPath" } Write-Host "Проверено файлов: $($files.Count), с ошибками: $bad" if ($bad -gt 0) { exit 1 }