Skip to content

Instantly share code, notes, and snippets.

@rsato rsato/
Last active Aug 27, 2019

What would you like to do?
Download YouTube video (youtube-dl wrapper)
# Dependencies:
# - youtube-dl
# - ffmpeg
# Preparing a "list.txt" that is a list of YouTube video IDs.
# (Video ID is a value of "v" key in YouTube URL: )
# Tips:
# - To expand IDs in the YouTube playlist, use "youtube-dl --get-id" command.
# $ youtube-dl --get-id > list.txt
for i in $(cat list.txt); do
# show ID and title
echo $i
youtube-dl -e$i
# download video
# format code extension resolution note
# 160 mp4 256x144 144p 117k , avc1.4d400c, 30fps, video only, 19.93MiB
# 136 mp4 1280x720 720p 2638k , avc1.4d401f, 30fps, video only, 437.53MiB
# 298 mp4 1280x720 720p60 4068k , avc1.4d4020, 60fps, video only, 654.95MiB
# 137 mp4 1920x1080 1080p 4949k , avc1.640028, 30fps, video only, 797.54MiB
# 299 mp4 1920x1080 1080p60 6766k , avc1.64002a, 60fps, video only, 1.08GiB
filename_mp4=$(youtube-dl -f 160 --get-filename$i)
for fmt in 299 137 298 136 ; do
if [ ! -e "$filename_mp4" ]; then
youtube-dl -i -w -f $fmt$i
# download audio
# format code extension resolution note
# 140 m4a audio only DASH audio 129k , m4a_dash container, mp4a.40.2@128k, 25.73MiB
filename_m4a=$(youtube-dl -f 140 --get-filename$i)
youtube-dl -i -w -f 140$i
# combine mp4 + m4a to out directory
mkdir -p out
if [ -e "$filename_mp4" -a -e "$filename_m4a" ]; then
ffmpeg -i "$filename_mp4" -i "$filename_m4a" -c copy "out/$filename_mp4"
# clean up
rm "$filename_mp4"
rm "$filename_m4a"

This comment has been minimized.

Copy link

sunyta2 commented Aug 27, 2019

impressive! wow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.