YouTubeMusicLibraryDownloader/ytmlibdl.ps1

36 lines
942 B
PowerShell
Raw Normal View History

2023-02-07 13:03:10 -04:00
# Save first arg and reparse to contain quotes
if (!$args) {
Write-Host "Input a playlist URL"
Exit 1
}
$videoURL = $args[0]
$videoURL = "$videoURL"
# Get status code to check for valid url
if ($videoURL.StartsWith("https://music.youtube.com/playlist")) {
$statusCode = Invoke-WebRequest $videoURL | % {$_.StatusCode}
} else {
Write-Host "Input a valid playlist URL"
Exit 1
}
# Documentation for output formats: https://github.com/yt-dlp/yt-dlp#output-template
if ($statusCode -eq 200) {
yt-dlp `
-f ba `
-x `
--audio-quality 0 `
--audio-format mp3 `
--embed-metadata `
-o "%(artist)s/%(album)s/%(playlist_index)s - %(track)s.%(ext)s" `
$videoURL
} else {
Write-Host "Input a valid playlist URL"
Exit 1
}
# To run, provide any youtube music url. For example: https://music.youtube.com/playlist?list=OLAK5uy_lYdwxvfKoDIiUba2_Dh1Pc-zOLLANCwKY