A bash wrapper script that prompts for the format, which includes all available renditions, including audio-only, video-only.
Accepts both absolute youtube URLs and video IDs.
#!/ usr/bin/env bash
# Download youtube video with desired quality
# Accept both full URLs and video id's such as AQcQgfvfF1M
# match by regex, starts with http:// or https://
if [[ "$1" =~ ^https?:\/\/.* ]]; then
url=$*
else
url="https://www.youtube.com/watch?v=$*"
fi
echo "Fetching available formats for $url..."
youtube-dl -F "$url"
read -p "Please enter the desired quality code: " FORMAT
echo "Streaming with quality $FORMAT..."
mpv --cache=1024 $(youtube-dl -f $FORMAT -g "$url")
Sample output:
yt.sh https://m.youtube.com/watch?v=Dax_tnZRExc
[youtube] Dax_tnZRExc: Downloading webpage
[youtube] Dax_tnZRExc: Downloading video info webpage
[youtube] Dax_tnZRExc: Extracting video information
[youtube] Dax_tnZRExc: Downloading MPD manifest
[info] Available formats for Dax_tnZRExc:
format code extension resolution note
139 m4a audio only DASH audio 49k , m4a_dash container, mp4a.40.5@ 48k (22050Hz), 308.75KiB
249 webm audio only DASH audio 50k , opus @ 50k, 271.91KiB
250 webm audio only DASH audio 70k , opus @ 70k, 366.63KiB
171 webm audio only DASH audio 118k , vorbis@128k, 652.50KiB
140 m4a audio only DASH audio 127k , m4a_dash container, mp4a.40.2@128k (44100Hz), 820.00KiB
251 webm audio only DASH audio 130k , opus @160k, 705.84KiB
160 mp4 256x144 DASH video 109k , avc1.4d400c, 13fps, video only, 703.64KiB
278 webm 256x144 144p 111k , webm container, vp9, 25fps, video only, 439.72KiB
242 webm 426x240 240p 243k , vp9, 25fps, video only, 623.95KiB
133 mp4 426x240 DASH video 252k , avc1.4d4015, 25fps, video only, 1.54MiB
134 mp4 640x360 DASH video 388k , avc1.4d401e, 25fps, video only, 1.24MiB
243 webm 640x360 360p 458k , vp9, 25fps, video only, 1.19MiB
135 mp4 854x480 DASH video 761k , avc1.4d401e, 25fps, video only, 2.40MiB
244 webm 854x480 480p 893k , vp9, 25fps, video only, 2.00MiB
136 mp4 1280x720 DASH video 1382k , avc1.4d401f, 25fps, video only, 4.56MiB
247 webm 1280x720 720p 1754k , vp9, 25fps, video only, 3.94MiB
137 mp4 1920x1080 DASH video 2350k , avc1.640028, 25fps, video only, 8.48MiB
248 webm 1920x1080 1080p 2792k , vp9, 25fps, video only, 8.09MiB
17 3gp 176x144 small , mp4v.20.3, mp4a.40.2@ 24k
36 3gp 320x180 small , mp4v.20.3, mp4a.40.2
43 webm 640x360 medium , vp8.0, vorbis@128k
18 mp4 640x360 medium , avc1.42001E, mp4a.40.2@ 96k
22 mp4 1280x720 hd720 , avc1.64001F, mp4a.40.2@192k (best)
Please enter the desired format #
If you want to download the video as opposed to stream it, just remove the mpv --cache=1024 part and the dollar sign with brackets.
manpage: "youtube-dl now defaults to downloading the highest available quality as reported by YouTube, which will be 1080p or 720p in some cases." – Jos Jun 21 '14 at 10:08