Записать название, исполнителя и альбом
Проставляет основные теги через ffmpeg и проверяет результат через ffprobe.
Что делает скрипт
Скрипт создаёт копию файла с новыми значениями title, artist и album, не меняя оригинал. Перед сохранением проверяет наличие ffmpeg и ffprobe, после записи читает теги обратно и показывает их. Подходит для пакетного исправления отдельных файлов.
Быстрый старт
powershell -File Set-AudioTags.ps1 -Path track.mp3 -Title "Intro" -Artist "Demo"
Скачайте файл, откройте терминал в папке со скриптом и выполните команду. Запускайте в PowerShell 5.1 или PowerShell 7.
Другие варианты
powershell -File Set-AudioTags.ps1 -Path track.mp3 -Title "Intro" -Artist "Demo" -Album "Live"powershell -File Set-AudioTags.ps1 -Path C:\Music\album -Title "Track" -Artist "Demo"
Что понадобится
Встроен в Windows 10/11 (PowerShell 5.1)
winget install Gyan.FFmpeg
Set-AudioTags.ps1
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[string]$Title,
[string]$Artist,
[string]$Album,
[string]$OutputDirectory,
[switch]$Force
)
$ErrorActionPreference = 'Stop'
if (-not $Title -and -not $Artist -and -not $Album) {
throw 'Укажите хотя бы один тег: -Title, -Artist или -Album.'
}
$ffmpeg = Get-Command ffmpeg -ErrorAction SilentlyContinue
$ffprobe = Get-Command ffprobe -ErrorAction SilentlyContinue
if (-not $ffmpeg -or -not $ffprobe) {
throw 'ffmpeg и ffprobe должны быть установлены.'
}
$resolved = Resolve-Path -LiteralPath $Path -ErrorAction Stop
$extensions = @('.mp3', '.flac', '.m4a', '.mp4', '.ogg', '.wav')
if (Test-Path -LiteralPath $resolved.Path -PathType Container) {
$root = $resolved.Path
$files = @(Get-ChildItem -LiteralPath $root -File -Recurse -ErrorAction SilentlyContinue |
Where-Object { $extensions -contains $_.Extension.ToLowerInvariant() })
if (-not $OutputDirectory) { $OutputDirectory = Join-Path $root 'tagged' }
} else {
$file = Get-Item -LiteralPath $resolved.Path
if ($extensions -notcontains $file.Extension.ToLowerInvariant()) {
throw "Формат не поддержан: $($file.Extension)"
}
$files = @($file)
if (-not $OutputDirectory) {
$OutputDirectory = Join-Path (Split-Path -Parent $file.FullName) 'tagged'
}
}
if ($files.Count -eq 0) {
Write-Host 'Аудиофайлы не найдены.'
exit 0
}
$outRoot = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputDirectory)
New-Item -ItemType Directory -Path $outRoot -Force | Out-Null
$done = 0
$skipped = 0
$failed = 0
foreach ($item in $files) {
$destination = Join-Path $outRoot ($item.BaseName + $item.Extension)
if ((Test-Path -LiteralPath $destination) -and -not $Force) {
Write-Host "Пропуск: $destination уже существует"
$skipped++
continue
}
if (-not $PSCmdlet.ShouldProcess($destination, 'Записать теги')) { continue }
$arguments = @('-hide_banner', '-loglevel', 'error', '-nostdin')
if ($Force) { $arguments += '-y' } else { $arguments += '-n' }
$arguments += @('-i', $item.FullName, '-map', '0', '-map_metadata', '0', '-c', 'copy')
if ($Title) { $arguments += @('-metadata', "title=$Title") }
if ($Artist) { $arguments += @('-metadata', "artist=$Artist") }
if ($Album) { $arguments += @('-metadata', "album=$Album") }
$arguments += $destination
& $ffmpeg.Source @arguments
if ($LASTEXITCODE -ne 0) {
Write-Host "Ошибка записи: $($item.FullName)" -ForegroundColor Red
$failed++
continue
}
$raw = & $ffprobe.Source -v quiet -print_format json -show_format $destination
if ($LASTEXITCODE -eq 0) {
$info = $raw | ConvertFrom-Json
$tags = $info.format.tags
if ($tags) {
Write-Host ("Теги: title={0}; artist={1}; album={2}" -f $tags.title, $tags.artist, $tags.album)
}
}
Write-Host "Готово: $destination"
$done++
}
Write-Host "Итог: готово $done, пропущено $skipped, ошибок $failed"
if ($failed -gt 0) { exit 2 }
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.