70

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.

Sam Vega
  • 821

5 Answers5

124

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

karel
  • 114,770
  • 1
    That 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) – Billal Begueradj Jan 28 '18 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? – Vicrobot Jul 18 '18 at 14:34
  • @Vicrobot I don't know if this is exactly your question, correct me if I'm wrong, but sometimes I download an entire series of programming tutorials from YouTube and I need to start it from the terminal, lock the screen, and leave it until it finishes. My other favorite source of knowledge is Leo Wattenberg who is YouTube Contributor, Google Top Contributor, YouTube Certified in channel growth and content strategy. Leo Wattenberg is also the top all time answerer of questions tagged with youtube at Web Applications Q&A. – karel Jul 18 '18 at 14:39
  • @karel I have a channel that contains about 250 videos. Now i want to download it. Is there any direct way to do these downloadings in partitions? – Vicrobot Jul 18 '18 at 14:42
  • Are they all in one channel or all in one playlist, then you can download the entire channel or playlist. Or else you can copy all the YouTube video links to a text file, each link on a separate line and download them all like this. – karel Jul 18 '18 at 14:47
  • @karel sorry for such stupid questions. I just figured out that it is itself taking care of previous downloads. :P – Vicrobot Jul 18 '18 at 14:47
  • I just want to note - as far as I can tell, all of the arguments are varying degrees of optional, and the default behavior if youtube-dl is given a channel is to download the whole channel. the most important addition here seems to me to be -ciw, which affect retry. – lahwran May 01 '19 at 19:27
  • 7
    You should also add --download-archive downloaded.txt to resume downloading - this will skip existing files – Tjorriemorrie Jun 25 '19 at 22:31
  • @tjorriemorrie could you please elaborate on how to modify this command youtube-dl -f best -ciw -o "%(title)s.%(ext)s" -v <url-of-channel> to use --download-archive downloaded.txt Thanks. – Jags Oct 18 '19 at 11:14
  • 2
    As 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. – nehem Nov 11 '19 at 13:08
  • @nehemiah I tested the -f best option of youtube-dl and it still works properly in my computer. By "works properly" I mean the -f best option downloads the best available resolution. Use a command of the form youtube-dl -F URL to list all of the available resolutions for the YouTube video at link URL. – karel Nov 11 '19 at 13:15
  • @karel I guess the issue could be in the way audio and video are combined. When I exclude the -f flag I'm noticing the best video and best audio are downloaded separately and merged using ffmpeg. When I include -f flag it directly downloads the .mp4 which is just 720p. I'm running youtube-dl version 2019.10.22 in MacOS Catalina. Apologies for not being an Ubuntu user in an Ubuntu forum. If it works, just great. Never mind – nehem Nov 11 '19 at 13:42
  • 1
    Wanted 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. – Julian Jocque May 10 '20 at 15:26
  • Thanks @JulianJocque for confirming that on Win10!! – degenerate Oct 17 '21 at 00:08
18

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.

smile-eh
  • 181
  • I would have made this a comment to the other thread, but you can't contribute without 50 reputation. – smile-eh Jun 01 '20 at 16:12
2

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

1

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>
cuppajoeman
  • 125
  • 5
0

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:

1

The app works with drag'n drop on Gnome,XFCE and KDE

kanehekili
  • 6,402