Closed humanfriend22 closed 10 months ago
#!/usr/bin/env bash
set -Eeuo pipefail
parse_params() {
args=("$@")
# check required params and arguments
[[ ${#args[@]} -eq 0 ]] && die "Missing script arguments"
echo "[]" > /tmp/youtube.json
youtubedr list https://www.youjsontube.com/watch\?list\=${args} -f json | \
jq '.Videos[] | .ID' | xargs -I {} \
sh -c "\
json=\$(cat /tmp/youtube.json);
(echo \"\$json\" | jq '.+=[{\"Video\":\"{}\"}]') > /tmp/youtube.json
"
json=$(cat /tmp/youtube.json);
for row in $(echo $json | jq -r '.[] | .Video'); do
info=$(youtubedr info -f json https://www.youtube.com/watch\?v\=$row)
itag=$(echo $info | jq '.Formats[0] | .Itag')
video_quality=$(echo $info | jq -r '.Formats[0]|.VideoQuality')
jq --arg video "$row" --arg itag "$itag" --arg video_quality "$video_quality" '(.[] | select(.Video==$video)) | {Video, Itag:$itag, VideoQuality:$video_quality}' /tmp/youtube.json
youtubedr download https://www.youtube.com/watch\?v\=$row \
-q ${itag}
done
return 0
}
parse_params "$@"
sudo chmod +x ~/youtube.sh
Parsing whole playlist and selecting highest video quality.
~/develop/youtube/youtube.sh PL9IEJIKnBJjEPxenuhKU7J5smY4XjFnyg ─╯
{
"Video": "a8mPKBxQ9No",
"Itag": "137",
"VideoQuality": "1080p"
}
4.64 MiB / 4.64 MiB 100 % [===================================================] 0s ] 1.86 GiB/s
{
"Video": "G5dNorAoeCM",
"Itag": "137",
"VideoQuality": "1080p"
}
Setting quality to empty string allows you to download the highest quality available. youtubedr download -q "" G208iCLwNN8
Videos have differing qualities, so I would like to download them at the highest quality available. How is this possible?