So I'm trying to download an entire youtube channel using youtube-dl. I know that if you use the -F command, it gives you a list of the quality type of the videos. My question is this: how to download the best quality of all the videos so the download doesnt default to 460p or something low like that.
5 Answers
This answer won't work on older versions of youtube-dl. You need to update youtube-dl to the latest version. You can either install the latest version of youtube-dl locally inside a Python virtual environment (virtualenv), or you can download the latest version of youtube-dl and install it with pip
(sudo apt remove youtube-dl && sudo apt install python-pip && pip install --user youtube-dl
). youtube-dl is also a snap package. To install it type:
sudo snap install youtube-dl # launch it with snap run youtube-dl
Open the terminal and type:
youtube-dl -f best -ciw -o "%(title)s.%(ext)s" -v <url-of-channel>
...where <url-of-channel>
is replaced by the URL of the channel.
Note: If you are downloading a lot of videos, you should change directories to the directory where you want to save the videos before you start downloading them.
Explanation
-f, --format FORMAT
video format code. The special name "best" will pick the best quality.
-c, --continue
force resume of partially downloaded files
-i, --ignore-errors
continue on download errors, for example to skip unavailable videos in a channel
-w, --no-overwrites
do not overwrite files
-o, --output
Output filename template, this example functions similarly to the old --title option
-v, --verbose
print various debugging information
-
1That was a good answer. Maybe if you just want to update it because I applied that command and I got this warning
WARNING: --title is deprecated. Use -o "%(title)s-%(id)s.%(ext)s"
(but your command worked successfully despite the warning) Commented Jan 28, 2018 at 11:00 -
@karel since the channel that i wanna download contains ,many videos thus i can't download them in one sitting. What to do in such case?– VicrobotCommented Jul 18, 2018 at 14:34
-
7You should also add
--download-archive downloaded.txt
to resume downloading - this will skip existing files Commented Jun 25, 2019 at 22:31 -
2As of today,
-f best
option WILL NOT give you the best resolution. You would be better off in removing that flag. Check with and without before queuing your batch download.– nehemCommented Nov 11, 2019 at 13:08 -
1Wanted to chime in and mirror what @nehem said. I'm on Windows 10 with the May 8th, 2020 build of youtube-dl and removing -f best did indeed bump the quality of the downloads significantly. Commented May 10, 2020 at 15:26
TL;DR use the -f 'bestvideo[height>=720]+bestaudio/best'
flag to get a higher resolution. The full command I used is:
youtube-dl -f "bestvideo[height>=720]+bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v <url-of-channel>
Here is why -f best
might not give you the highest resolution.
When you use the -F
flag to list the possible file formats, sometimes it lists a 360p format as "best", for example:
youtube-dl -F https://www.youtube.com/watch?v=FmZXCqqx6q0
[youtube] FmZXCqqx6q0: Downloading webpage
[info] Available formats for FmZXCqqx6q0:
format code extension resolution note
249 webm audio only tiny 61k , opus @ 50k (48000Hz), 12.74MiB
250 webm audio only tiny 80k , opus @ 70k (48000Hz), 16.87MiB
140 m4a audio only tiny 132k , m4a_dash container, mp4a.40.2@128k (44100Hz), 31.35MiB
251 webm audio only tiny 158k , opus @160k (48000Hz), 33.34MiB
...
244 webm 854x480 480p 271k , vp9, 30fps, video only, 35.05MiB
398 mp4 1280x720 720p 443k , av01.0.05M.08, 30fps, video only, 102.27MiB
247 webm 1280x720 720p 480k , vp9, 30fps, video only, 63.02MiB
136 mp4 1280x720 720p 489k , avc1.4d401f, 30fps, video only, 114.12MiB
18 mp4 640x360 360p 360k , avc1.42001E, 30fps, mp4a.40.2@ 96k (44100Hz), 87.29MiB (best)
As you can see the last option is listed as the best despite it's low resolution. There are a few ways we can get around this, I was trying to download from a channel that uploads in 720p so the easiest way was for me to use the -f 'bestvideo[height>=720]+bestaudio/best'
flag.
Depending on your situation you might have to play with the format selector expression, perhaps either increasing it from 720 to 1080 or selecting a specific file format like mp4.
To see other format selector examples
To see a full breakdown of the options
You will need to install ffmpeg or convert from mkv.
-
I would have made this a comment to the other thread, but you can't contribute without 50 reputation.– smile-ehCommented Jun 1, 2020 at 16:12
You can use this with youtube-dl
.
But I recommend yt-dlp
, it provides better download speed.
Example of Batch script for Windows.
Can be also adapted for Linux Bash.
Inspiration from Linux Bash script https://askubuntu.com/a/1022993/803975
@ECHO OFF
REM Downloads Video, converts into MKV and embeds subtitles
REM https://askubuntu.com/questions/1022855/download-everything-from-a-youtube-video-using-youtube-dl/1022993#1022993
IF NOT EXIST "./archive/videos/TZM_Archive/" MKDIR "./archive/videos/TZM_Archive/"
IF NOT EXIST "./archive/videos/TZM_Archive/TZM_Archive.ytdlarchive" ECHO. > "./archive/videos/TZM_Archive/TZM_Archive.ytdlarchive"
yt-dlp ^
--retries "3" ^
--no-overwrites ^
--call-home ^
--write-info-json ^
--write-description ^
--write-thumbnail ^
--all-subs ^
--convert-subs "srt" ^
--write-annotations ^
--add-metadata ^
--embed-subs ^
--download-archive "./archive/videos/TZM_Archive/TZM_Archive.ytdlarchive" ^
--format "bestvideo+bestaudio/best" ^
--merge-output-format "mkv" ^
--output "./archive/videos/TZM_Archive/%%(upload_date)s_%%(id)s/TZM_Archive_%%(upload_date)s_%%(id)s_%%(title)s.%%(ext)s" ^
"https://www.youtube.com/user/TZMOfficialChannel/videos"
IF NOT EXIST "./archive/videos/TZM_Archive/TZM_Archive.ytdlarchive" ECHO. > "./archive/videos/TZM_Archive/TZM_Archive_subtitles.ytdlarchive"
REM Downloads additional externally available SUBTITLES to the folder of downloaded video
yt-dlp ^
--skip-download ^
--retries "3" ^
--call-home ^
--all-subs ^
--convert-subs "srt" ^
--output "./archive/videos/TZM_Archive/%%(upload_date)s_%%(id)s/TZM_Archive_%%(upload_date)s_%%(id)s_%%(title)s.%%(ext)s" ^
"https://www.youtube.com/user/TZMOfficialChannel/videos"
REM Downloads additional and missing THUMBNAILS
yt-dlp ^
--skip-download ^
--write-all-thumbnails ^
--ignore-config ^
--id ^
--output "./archive/videos/TZM_Archive/%%(upload_date)s_%%(id)s/TZM_Archive_%%(upload_date)s_%%(id)s_%%(title)s.%%(ext)s" ^
"https://www.youtube.com/user/TZMOfficialChannel/videos"
PAUSE
The other two answers provide a good way to download all the videos from a youtube channel, but something that might come up is wanting to re-download the videos from a channel to get new videos they might have posted.
youtube-dl
comes with an option which allows for this called --download-archive
, it allows you to give a file which stores the videos you've already downloaded and then makes sure not to re-download them. It also writes to this file as it downloads new videos.
First we have to create this file for the videos we've already downloaded:
create_download_list.sh
:
#!/usr/bin/env bash
for n in *.*
do if [[ "$n" =~ -([-_0-9a-zA-Z]{11}).*$ ]]
then echo "youtube ${BASH_REMATCH[1]}"
fi
done > downloaded.txt
Now when you want to fetch new videos from the channel, you would just have to run:
youtube-dl --download-archive downloaded.txt ... <url-of-channel>
A little late, I'd like to propose my ytdownloader, which I offer as ppa for Ubuntu users:
sudo add-apt-repository ppa:jentiger-moratai/mediatools
sudo apt update
sudo apt install ytdownloader
As all of my apps, I try to keep the UI as simple as possible. The ytdownlaoder has been written to download the best quality video and audio (possibly using different servers)- it's backend is yt-dlp:
The app works with drag'n drop on Gnome,XFCE and KDE