71

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
  • 831

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
  • 122,292
  • 133
  • 301
  • 332
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
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>
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
  • 7,426