| name | music-download |
| description | Download music from YouTube and other sites using yt-dlp + ffmpeg. Extract audio as MP3 with consistent naming and folder structure. Naming convention: Title - Artist. Supports single tracks, playlists, and batch downloads. Use when the user says "download this song", "โหลดเพลงนี้ให้หน่อย", "add this music", or provides a URL to download music from.
|
Music Download
Download music from YouTube and other supported sites into a local collection.
Naming convention: {Title} - {Artist}.mp3 (ชื่อเพลงขึ้นก่อน)
Prerequisites
yt-dlp — installed (check with yt-dlp --version)
ffmpeg — installed (check with ffmpeg -version)
- Target directory — ask user on first use
Configuration
Default music directory: D:\เพลง\เพลงรัก
The script uses --parse-metadata "title:%(artist)s - %(track)s" to extract artist and track name from YouTube titles (which are typically Artist - Title), then outputs as Title - Artist.mp3.
Commands
Single Track Download
yt-dlp `
--extract-audio `
--audio-format mp3 `
--audio-quality 0 `
--embed-thumbnail `
--add-metadata `
--parse-metadata "title:%(artist)s - %(track)s" `
-o "$musicDir\%(track)s - %(artist)s.%(ext)s" `
"<URL>"
Fallback: if the title doesn't contain -, the file saves as the original title.
Lossless (FLAC)
yt-dlp `
--extract-audio `
--audio-format flac `
--audio-quality 0 `
--embed-thumbnail `
--add-metadata `
--parse-metadata "title:%(artist)s - %(track)s" `
-o "$musicDir\%(track)s - %(artist)s.%(ext)s" `
"<URL>"
Download Playlist
yt-dlp `
--extract-audio `
--audio-format mp3 `
--audio-quality 0 `
--embed-thumbnail `
--add-metadata `
--parse-metadata "title:%(artist)s - %(track)s" `
--yes-playlist `
--ignore-errors `
-o "$musicDir\%(playlist_index)s - %(track)s - %(artist)s.%(ext)s" `
"<playlist_URL>"
Rename Existing Files (Artist - Title → Title - Artist)
Use this to batch-rename existing files in the collection to the new standard:
$musicDir = "D:\เพลง\เพลงรัก"
Get-ChildItem "$musicDir" -Filter "*.mp3" -File | Where-Object {
$_.Name -match '^(.+?) - (.+)\.mp3$'
} | ForEach-Object {
$artist = $matches[1]
$title = $matches[2]
# Skip if already in Title - Artist format
if ($title -match ' - ') { return }
$newName = "$title - $artist.mp3"
$newPath = Join-Path $_.Directory $newName
if (-not (Test-Path $newPath)) {
Rename-Item -LiteralPath $_.FullName -NewName $newName
Write-Host "Renamed: $($_.Name) → $newName"
}
}
Post-Download Duplicate Check
Get-ChildItem "$musicDir" -Filter "*.mp3" -File | ForEach-Object {
$base = $_.Name -replace '【[^】]*】', '' -replace '[♫♪\||⧸\-\.\[\]\(\)]', ' '
$normalized = ($base -replace '\s+', ' ').Trim().ToLower()
[PSCustomObject]@{ Path = $_.FullName; Name = $_.Name; Normalized = $normalized }
} | Group-Object Normalized | Where-Object Count -gt 1 | ForEach-Object {
Write-Host "`nDuplicate: $($_.Name)"
$_.Group | ForEach-Object { Write-Host " $($_.Path)" }
}
Naming Convention
| Format | Example |
|---|
{Title} - {Artist}.mp3 | 瞬 - 鄭潤澤.mp3 |
{Title}.mp3 (no artist) | Instrumental.mp3 |
{Index} - {Title} - {Artist}.mp3 (playlist) | 03 - 瞬 - 鄭潤澤.mp3 |
Supported Sites
YouTube, YouTube Music, SoundCloud, Bandcamp, Vimeo, and 1000+ sites supported by yt-dlp.