[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [string]$Csv, [ValidateRange(8, 1024)] [int]$LowKbps = 128, [ValidateRange(1, 3600)] [int]$MinDuration = 5 ) $ErrorActionPreference = 'Stop' $ffprobe = Get-Command ffprobe -ErrorAction SilentlyContinue if (-not $ffprobe) { throw 'ffprobe не найден. Установите FFmpeg через winget.' } $resolved = Resolve-Path -LiteralPath $Path -ErrorAction Stop $extensions = @('.mp3', '.wav', '.flac', '.ogg', '.m4a', '.aac', '.wma') 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 } $records = @() foreach ($file in $files) { $raw = & $ffprobe.Source -v quiet -print_format json -show_format -show_streams $file.FullName if ($LASTEXITCODE -ne 0) { Write-Host "Пропуск: $($file.FullName)" -ForegroundColor Red continue } try { $info = $raw | ConvertFrom-Json } catch { Write-Host "Пропуск: $($file.FullName): некорректный JSON" -ForegroundColor Red continue } $audio = @($info.streams | Where-Object { $_.codec_type -eq 'audio' }) | Select-Object -First 1 if (-not $audio) { Write-Host "Пропуск: нет аудиопотока в $($file.FullName)" -ForegroundColor Red continue } $bitrate = [int64]0 if ($audio.bit_rate) { [void][int64]::TryParse([string]$audio.bit_rate, [ref]$bitrate) } if ($bitrate -le 0 -and $info.format.bit_rate) { [void][int64]::TryParse([string]$info.format.bit_rate, [ref]$bitrate) } $kbps = if ($bitrate -gt 0) { [math]::Round($bitrate / 1000, 0) } else { 0 } $duration = 0.0 if ($info.format.duration) { [void][double]::TryParse([string]$info.format.duration, [ref]$duration) } $tags = $info.format.tags $artist = if ($tags -and $tags.artist) { [string]$tags.artist } else { '' } $title = if ($tags -and $tags.title) { [string]$tags.title } else { '' } $flags = @() if ($kbps -gt 0 -and $kbps -lt $LowKbps) { $flags += 'низкий битрейт' } if ($duration -gt 0 -and $duration -lt $MinDuration) { $flags += 'короткий файл' } $records += [pscustomobject]@{ File = $file.FullName Codec = [string]$audio.codec_name BitrateKbps = $kbps SampleRate = [int]$audio.sample_rate Channels = [int]$audio.channels DurationSec = [math]::Round($duration, 2) SizeMB = [math]::Round($file.Length / 1MB, 2) Artist = $artist Title = $title Flags = ($flags -join '; ') } } if ($records.Count -eq 0) { Write-Host 'Не удалось прочитать ни одного файла.' exit 1 } $records | Format-Table File, Codec, BitrateKbps, SampleRate, Channels, DurationSec, Flags -AutoSize $low = @($records | Where-Object { $_.Flags -match 'низкий' }).Count $short = @($records | Where-Object { $_.Flags -match 'короткий' }).Count Write-Host "Файлов: $($records.Count), с низким битрейтом: $low, коротких: $short" if ($Csv) { $csvPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Csv) $records | Export-Csv -LiteralPath $csvPath -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $csvPath" }