Download everything from a YouTube video using youtube-dl
Solution 1:
The relevant options you need:
# Filesystem
--write-annotations
--write-description
--write-info-json
# Thumbnail images
--write-all-thumbnails
# Video format
--format bestvideo+bestaudio/best
--merge-output-format mkv
# Subtitle
--all-subs
--write-auto-sub
--write-sub
# Post-processing
--add-metadata
--embed-subs
Copy that to your config file (either /etc/youtube-dl.conf
or ~/.config/youtube-dl/config
).
Using that configuration, I downloaded this video and youtube-dl
wrote the following files:
$ ls
The Problem with Time & Timezones - Computerphile.annotations.xml
The Problem with Time & Timezones - Computerphile.description
The Problem with Time & Timezones - Computerphile.info.json
The Problem with Time & Timezones - Computerphile.jpg
The Problem with Time & Timezones - Computerphile.mkv
I can't post mediainfo
's output here because it exceeds the characters limit, but you can see it in github.
I also want to download the video/audio in the highest quality possible, with no quality loss.
youtube-dl
downloads videos at the highest quality possible by default, but you can force this behavior using --format bestvideo+bestaudio/best
.
Even though it's not YouTube, I did also want to download some of my udemy courses I've bought so I can watch them while I'm on a long road trip.
Please read the article Can I Download a Course to my Computer?:
By default, complete courses are not downloadable from a computer. We do this out of concerns for piracy.
Please note that you can always save courses for offline viewing on the Udemy mobile app. For information on how to download video lectures to your iOS mobile device, please click here. For steps on how to download videos for offline viewing on an Android device, click here.
I have
ffmpeg
installed, and I heard that you need this for lossless downloads from YouTube, but I'm not sure how to link it withyoutube-dl
.
youtube-dl
uses avconv
by default, but --prefer-ffmpeg
let you use ffmpeg
instead. Anyway, this option is not needed for "lossless downloads". In the example I provided, youtube-dl
only used ffmpeg
to merge all the downloaded formats into a single mkv file.
Solution 2:
To simply download the video, you can use this:
youtube-dl --all-subs "https://www.youtube.com/watch?v=KYBok-XGsKM"
To select the video quality, you should first use the -F option to list the available formats.
youtube-dl -F "https://www.youtube.com/watch?v=KYBok-XGsKM"
And this is the output for your video:
[youtube] KYBok-XGsKM: Downloading webpage
[youtube] KYBok-XGsKM: Downloading video info webpage
[youtube] KYBok-XGsKM: Extracting video information
WARNING: unable to extract uploader nickname
[info] Available formats for KYBok-XGsKM:
format code extension resolution note
249 webm audio only DASH audio 52k , opus @ 50k, 4.19MiB
250 webm audio only DASH audio 75k , opus @ 70k, 5.42MiB
140 m4a audio only DASH audio 129k , m4a_dash container, mp4a.40.2@128k, 10.59MiB
171 webm audio only DASH audio 131k , vorbis@128k, 7.66MiB
251 webm audio only DASH audio 135k , opus @160k, 9.58MiB
278 webm 256x144 144p 98k , webm container, vp9, 30fps, video only, 6.59MiB
160 mp4 256x144 144p 114k , avc1.4d400c, 15fps, video only, 9.04MiB
242 webm 426x240 240p 205k , vp9, 30fps, video only, 11.47MiB
133 mp4 426x240 240p 265k , avc1.4d4015, 30fps, video only, 20.11MiB
243 webm 640x360 360p 362k , vp9, 30fps, video only, 21.93MiB
134 mp4 640x360 360p 602k , avc1.4d401e, 30fps, video only, 20.42MiB
244 webm 854x480 480p 662k , vp9, 30fps, video only, 37.82MiB
135 mp4 854x480 480p 1020k , avc1.4d401f, 30fps, video only, 42.62MiB
247 webm 1280x720 720p 1353k , vp9, 30fps, video only, 81.53MiB
136 mp4 1280x720 720p 2013k , avc1.4d401f, 30fps, video only, 84.69MiB
137 mp4 1920x1080 1080p 2438k , avc1.640028, 30fps, video only, 157.71MiB
248 webm 1920x1080 1080p 2593k , vp9, 30fps, video only, 162.48MiB
264 mp4 2560x1440 1440p 6973k , avc1.640032, 30fps, video only, 459.58MiB
271 webm 2560x1440 1440p 7523k , vp9, 30fps, video only, 485.66MiB
313 webm 3840x2160 2160p 19991k , vp9, 30fps, video only, 1.34GiB
36 3gp 320x? small , mp4v.20.3, mp4a.40.2
17 3gp 176x144 small , mp4v.20.3, mp4a.40.2@ 24k
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)
Here are some useful options for subtitles:
--write-sub
Write subtitle file
--write-auto-sub
Write automatically generated subtitle file (YouTube only)
--all-subs
Download all the available subtitles of the video
--list-subs
List all available subtitles for the video
And for thumbnails:
--write-thumbnail
Write thumbnail image to disk
--write-all-thumbnails
Write all thumbnail image formats to disk
--list-thumbnails
Simulate and list all available thumbnail formats
You can also find more information about the quality of video here