Created
March 29, 2020 21:18
-
-
Save hdurdle/38b02477ae69e64e59c8843c0d6e7f60 to your computer and use it in GitHub Desktop.
Powershell to get best quality video and audio using youtube-dl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[Parameter(Mandatory=$true)] | |
[string]$url | |
) | |
# run in a directory that contains youtube-dl.exe and ffmpeg.exe | |
$qualityList = `.\youtube-dl.exe -F $url` | |
$videoOnly = $qualityList | Select-String -Pattern 'video only' -CaseSensitive -SimpleMatch | |
$best = $videoOnly[$videoOnly.length-1] | |
if ($best -like '*mp4*') { | |
$params = " -f bestvideo[ext=mp4]+bestaudio[ext=m4a] $url" | |
} elseif ($best -like '*webm*') { | |
$params = " -f bestvideo[ext=webm]+bestaudio[ext=webm] $url" | |
} else { | |
Write-Output "Unknown type." | |
exit 1 | |
} | |
$command = ".\youtube-dl.exe" | |
$paramsSplit = $params.Split(" ") | |
& "$command" $paramsSplit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment