Watch YouTube videos using youtube-dl

Watching YouTube videos requires the user to run nonfree JavaScript. It also requires more system resources than downloading the videos and viewing them with a video player, such as mpv or an Invidious instance.

yt-dlp is free software and is capable of downloading videos from YouTube and other video websites.

Installing yt-dlp

  • Open Terminal
  • Use the following command to download the yt-dlp program:
    sudo apt install yt-dlp
    
  • Update to a more recent version:
    sudo yt-dlp -U
    

Do this step whenever yt-dlp stops working due to changes in the YouTube website.

  • The first time you update yt-dlp using this method, you will need to run it as root:
    sudo yt-dlp
    

Now, you can use the yt-dlp command to download YouTube videos. First, find out which formats are available by using the following command and replacing the shown URL with the URL of the video you wish to download.

yt-dlp -F https://www.youtube.com/watch?v=9tgkpDwS97I
The output will look like this:
[youtube] Extracting URL: https://www.youtube.com/watch?v=9tgkpDwS97I
[youtube] 9tgkpDwS97I: Downloading webpage
[youtube] 9tgkpDwS97I: Downloading tv client config
[youtube] 9tgkpDwS97I: Downloading tv player API JSON
[youtube] 9tgkpDwS97I: Downloading ios player API JSON
[youtube] 9tgkpDwS97I: Downloading m3u8 information
[info] Available formats for 9tgkpDwS97I:
ID      EXT   RESOLUTION FPS CH │   FILESIZE    TBR PROTO │ VCODEC           VBR ACODEC      
─────────────────────────────────────────────────────────────────────────────────────────────
sb2     mhtml 48x27        1    │                   mhtml │ images                     
sb1     mhtml 80x45        1    │                   mhtml │ images              
sb0     mhtml 160x90       1    │                   mhtml │ images             
233     mp4   audio only        │                   m3u8  │ audio only           unknown
234     mp4   audio only        │                   m3u8  │ audio only           unknown
249-drc webm  audio only      2 │  440.26KiB    51k https │ audio only           opus     
250-drc webm  audio only      2 │  493.85KiB    57k https │ audio only           opus     
249     webm  audio only      2 │  439.09KiB    51k https │ audio only           opus     
250     webm  audio only      2 │  493.41KiB    57k https │ audio only           opus     
140-drc m4a   audio only      2 │    1.10MiB   130k https │ audio only           mp4a.40.2  
251-drc webm  audio only      2 │  889.85KiB   102k https │ audio only           opus       
140     m4a   audio only      2 │    1.08MiB   127k https │ audio only           mp4a.40.2  
251     webm  audio only      2 │  889.84KiB   102k https │ audio only           opus       
269     mp4   256x144     30    │ ~758.70KiB    88k m3u8  │ avc1.4D400C      88k video only
160     mp4   256x144     30    │  226.99KiB    26k https │ avc1.4d400c      26k video only 
603     mp4   256x144     30    │ ~  1.29MiB   152k m3u8  │ vp09.00.11.08   152k video only
278     webm  256x144     30    │  744.37KiB    86k https │ vp9              86k video only
229     mp4   426x240     30    │ ~  1.03MiB   122k m3u8  │ avc1.4D4015     122k video only
133     mp4   426x240     30    │  429.82KiB    49k https │ avc1.4d4015      49k video only
604     mp4   426x240     30    │ ~  2.00MiB   237k m3u8  │ vp09.00.20.08   237k video only
242     webm  426x240     30    │    1.02MiB   121k https │ vp9             121k video only 
230     mp4   640x360     30    │ ~  3.03MiB   359k m3u8  │ avc1.4D401E     359k video only
134     mp4   640x360     30    │    1.28MiB   151k https │ avc1.4d401e     151k video only 
18      mp4   640x360     30  2 │ ≈  2.36MiB   278k https │ avc1.42001E          mp4a.40.2
605     mp4   640x360     30    │ ~  4.55MiB   538k m3u8  │ vp09.00.21.08   538k video only
243     webm  640x360     30    │    2.26MiB   267k https │ vp9             267k video only
231     mp4   854x480     30    │ ~  5.80MiB   685k m3u8  │ avc1.4D401F     685k video only
135     mp4   854x480     30    │    3.07MiB   362k https │ avc1.4d401f     362k video only
606     mp4   854x480     30    │ ~  7.65MiB   904k m3u8  │ vp09.00.30.08   904k video only
244     webm  854x480     30    │    4.30MiB   507k https │ vp9             507k video only
232     mp4   1280x720    30    │ ~ 13.24MiB  1564k m3u8  │ avc1.4D401F    1564k video only
136     mp4   1280x720    30    │    7.70MiB   907k https │ avc1.4d401f     907k video only
609     mp4   1280x720    30    │ ~ 14.61MiB  1726k m3u8  │ vp09.00.31.08  1726k video only
247     webm  1280x720    30    │    9.70MiB  1143k https │ vp9            1143k video only
270     mp4   1920x1080   30    │ ~ 25.74MiB  3041k m3u8  │ avc1.640028    3041k video only
137     mp4   1920x1080   30    │   15.51MiB  1829k https │ avc1.640028    1829k video only
614     mp4   1920x1080   30    │ ~ 24.90MiB  2942k m3u8  │ vp09.00.40.08  2942k video only
248     webm  1920x1080   30    │   18.04MiB  2127k https │ vp9            2127k video only
620     mp4   2560x1440   30    │ ~ 80.13MiB  9467k m3u8  │ vp09.00.50.08  9467k video only
271     webm  2560x1440   30    │   57.86MiB  6819k https │ vp9            6819k video only
625     mp4   3840x2160   30    │ ~157.76MiB 18639k m3u8  │ vp09.00.50.08 18639k video only
313     webm  3840x2160   30    │  137.47MiB 16203k https │ vp9           16203k video only
571     mp4   7680x4320   60    │  324.97MiB 29978k https │ av01.0.17M.08 29978k video only
Unfortunately, the video may come in a patent-encumbered format, like MP4. To receive videos in a free format like WebM, you may use the flag --prefer-free-formats .

Some examples below:

  • Download the video in SD 480p resolution (854x480):
    yt-dlp -S "res:480" --prefer-free-formats https://www.youtube.com/watch?v=9tgkpDwS97I
    
  • Download the video in HD 720p resolution (1280x720):
    yt-dlp -S "res:720" --prefer-free-formats https://www.youtube.com/watch?v=9tgkpDwS97I
    
  • Download the video in Full HD 1080p resolution (1920x1080):
    yt-dlp -S "res:1080" --prefer-free-formats https://www.youtube.com/watch?v=9tgkpDwS97I
    
  • Download the video in 4K Ultra HD 2160p resolution (3840x2160):
    yt-dlp -S "res:2160" --prefer-free-formats https://www.youtube.com/watch?v=9tgkpDwS97I
    
  • Download the video in 8K Ultra HD 4320p resolution (7680x4320):
    yt-dlp -S "res:4320" --prefer-free-formats https://www.youtube.com/watch?v=6CKw76cURpc
    

yt-dlp will then start downloading the video. The output will look something like this:

[youtube] Extracting URL: https://www.youtube.com/watch?v=9tgkpDwS97I
[youtube] 9tgkpDwS97I: Downloading webpage
[youtube] 9tgkpDwS97I: Downloading tv client config
[youtube] 9tgkpDwS97I: Downloading tv player API JSON
[youtube] 9tgkpDwS97I: Downloading ios player API JSON
[youtube] 9tgkpDwS97I: Downloading m3u8 information
[info] 9tgkpDwS97I: Downloading 1 format(s): 313+251
[download] Resuming download at byte 31410150
[download] Destination: Richard Stallman: SHOW ME THE MONEY! [9tgkpDwS97I].f313.webm
[download] 100% of  137.47MiB in 00:00:23 at 5.84MiB/s
[download] Destination: Richard Stallman: SHOW ME THE MONEY! [9tgkpDwS97I].f251.webm
[download] 100% of  889.84KiB in 00:00:00 at 1.07MiB/s
[Merger] Merging formats into "Richard Stallman: SHOW ME THE MONEY! [9tgkpDwS97I].webm"
Deleting original file Richard Stallman: SHOW ME THE MONEY! [9tgkpDwS97I].f313.webm (pass -k to keep)
Deleting original file Richard Stallman: SHOW ME THE MONEY! [9tgkpDwS97I].f251.webm (pass -k to keep)

Alternative way for installing/upgrading yt-dlp

There is another way to have yt-dlp installed, using the pip Python package manager/installer:
sudo apt install python-pip
sudo pip install yt-dlp
Upgrading is as simple as
sudo pip install -U yt-dlp

Revisions

11/22/2012 - 08:51
andrew
07/08/2013 - 07:55
aloniv
08/13/2013 - 19:19
lloydsmart
02/05/2014 - 19:51
ssdclickofdeath
09/04/2014 - 03:53
muhammed
10/09/2014 - 12:07
a1l3erto
08/17/2017 - 06:43
calher
09/21/2024 - 15:35
knife
03/16/2025 - 19:03
Luck-02
04/20/2025 - 07:15
icarolongo