Skip to content

Instantly share code, notes, and snippets.

@hdurdle
Created March 29, 2020 21:18
Show Gist options
  • Save hdurdle/38b02477ae69e64e59c8843c0d6e7f60 to your computer and use it in GitHub Desktop.
Save hdurdle/38b02477ae69e64e59c8843c0d6e7f60 to your computer and use it in GitHub Desktop.
Powershell to get best quality video and audio using youtube-dl
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