Bookmark and Share



Downloading YouTube, Vimeo etc Videos using youtube-dl - 2020



What is youtube-dl

Written in Python, the youtube-dl is one of the most popular tools for downloading videos not only from YouTube but from other sources such as Vimeo.

The list of sites that we can download is available from Supported sites.

  1. How to download youtube-dl?
    $ sudo curl https://yt-dl.org/downloads/2016.01.09/youtube-dl -o /usr/local/bin/youtube-dl
    
    Or
    $ sudo wget https://yt-dl.org/downloads/2016.01.14/youtube-dl -O /usr/local/bin/youtube-dl
    
  2. Set a executable execute permission
    $ sudo chmod a+x /usr/local/bin/youtube-dl
    
  3. How to use it to download YouTube video?
    To download a video file, simply run the following command. All we need is the url of the video that we want to download.
    $ youtube-dl https://www.youtube.com/watch?v=dP15zlyra3c
    [youtube] dP15zlyra3c: Downloading webpage
    [youtube] dP15zlyra3c: Downloading video info webpage
    [youtube] dP15zlyra3c: Extracting video information
    [youtube] dP15zlyra3c: Downloading DASH manifest
    [youtube] dP15zlyra3c: Downloading DASH manifest
    [download] Destination: Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.f137.mp4
    [download] 100% of 13.25MiB in 00:06
    [download] Destination: Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.f141.m4a
    [download] 100% of 1.78MiB in 00:01
    [ffmpeg] Merging formats into "Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.mp4"
    Deleting original file Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.f137.mp4 (pass -k to keep)
    Deleting original file Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.f141.m4a (pass -k to keep)
    
    $ ls
    Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.mp4
    
  4. Downloading done!
    $ ls
    Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.mp4
    

  5. List of available formats
    $ youtube-dl --list-formats https://www.youtube.com/watch?v=dP15zlyra3c
    [youtube] dP15zlyra3c: Downloading webpage
    [youtube] dP15zlyra3c: Downloading video info webpage
    [youtube] dP15zlyra3c: Extracting video information
    [youtube] dP15zlyra3c: Downloading DASH manifest
    [youtube] dP15zlyra3c: Downloading DASH manifest
    [info] Available formats for dP15zlyra3c:
    format code  extension  resolution note
    171          webm       audio only DASH audio  118k , vorbis@128k (44100Hz), 761.87KiB
    140          m4a        audio only DASH audio  129k , m4a_dash container, aac  @128k (44100Hz), 916.53KiB
    141          m4a        audio only DASH audio  255k , m4a_dash container, aac  @256k (44100Hz), 1.78MiB
    160          mp4        256x144    DASH video  111k , avc1.4d400c, 13fps, video only, 785.14KiB
    242          webm       426x240    DASH video  114k , vp9, 1fps, video only, 570.74KiB
    243          webm       640x360    DASH video  203k , vp9, 1fps, video only, 1009.74KiB
    133          mp4        426x240    DASH video  247k , avc1.4d4015, 25fps, video only, 1.69MiB
    134          mp4        640x360    DASH video  251k , avc1.4d401e, 25fps, video only, 1.23MiB
    244          webm       854x480    DASH video  368k , vp9, 1fps, video only, 1.81MiB
    135          mp4        854x480    DASH video  542k , avc1.4d401e, 25fps, video only, 2.78MiB
    247          webm       1280x720   DASH video  622k , vp9, 1fps, video only, 3.35MiB
    136          mp4        1280x720   DASH video 1163k , avc1.4d401f, 25fps, video only, 6.50MiB
    248          webm       1920x1080  DASH video 1171k , vp9, 1fps, video only, 6.80MiB
    137          mp4        1920x1080  DASH video 2087k , avc1.640028, 25fps, video only, 13.25MiB
    17           3gp        176x144    small ,  mp4a.40.2, mp4v.20.3
    36           3gp        320x240    small ,  mp4a.40.2, mp4v.20.3
    5            flv        400x240    small 
    43           webm       640x360    medium ,  vorbis, vp8.0
    18           mp4        640x360    medium ,  mp4a.40.2, avc1.42001E
    22           mp4        1280x720   hd720 ,  mp4a.40.2, avc1.64001F (best)
    
  6. To download a preferred file format, use the option -f (video format code). For example, if we want to download webm format, we use 43 as shown below:
    $ youtube-dl -f 43 https://www.youtube.com/watch?v=dP15zlyra3c
    [youtube] dP15zlyra3c: Downloading webpage
    [youtube] dP15zlyra3c: Downloading video info webpage
    [youtube] dP15zlyra3c: Extracting video information
    [youtube] dP15zlyra3c: Downloading DASH manifest
    [youtube] dP15zlyra3c: Downloading DASH manifest
    [download] Destination: Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.webm
    [download] 100% of 3.47MiB in 00:02
    

    Now we have two videos in different formats in our folder - mp4 and webm:

    $ ls
    Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.mp4  
    Fox Snow Dive - Yellowstone - BBC Two-dP15zlyra3c.webm
    
  7. To download a list of videos, we can use a playlist. Just add the playlist URL:
    $ youtube-dl https://www.youtube.com/playlist?list=PLZI6KTHH6719oHLU-Sk3ViuIWJ-G7awXP
    [youtube:playlist] PLZI6KTHH6719oHLU-Sk3ViuIWJ-G7awXP: Downloading webpage
    [download] Downloading playlist: quantum-testing-shorts
    [youtube:playlist] playlist quantum-testing-shorts: Downloading 2 videos
    [download] Downloading video 1 of 2
    [youtube] DZGINaRUEkU: Downloading webpage
    [youtube] DZGINaRUEkU: Downloading video info webpage
    [youtube] DZGINaRUEkU: Extracting video information
    [youtube] DZGINaRUEkU: Downloading DASH manifest
    [youtube] DZGINaRUEkU: Downloading DASH manifest
    [download] Destination: Symphony of Science - the Quantum World!-DZGINaRUEkU.f136.mp4
    [download] 100% of 42.40MiB in 00:25
    [download] Destination: Symphony of Science - the Quantum World!-DZGINaRUEkU.f141.m4a
    [download] 100% of 6.33MiB in 00:03
    [ffmpeg] Merging formats into "Symphony of Science - the Quantum World!-DZGINaRUEkU.mp4"
    Deleting original file Symphony of Science - the Quantum World!-DZGINaRUEkU.f136.mp4 (pass -k to keep)
    Deleting original file Symphony of Science - the Quantum World!-DZGINaRUEkU.f141.m4a (pass -k to keep)
    [download] Downloading video 2 of 2
    [youtube] JQobzUqaR4U: Downloading webpage
    [youtube] JQobzUqaR4U: Downloading video info webpage
    [youtube] JQobzUqaR4U: Extracting video information
    [youtube] JQobzUqaR4U: Downloading DASH manifest
    [youtube] JQobzUqaR4U: Downloading DASH manifest
    [download] Destination: Quantum computer coding in silicon now possible-JQobzUqaR4U.f248.webm
    [download] 100% of 17.37MiB in 00:14
    [download] Destination: Quantum computer coding in silicon now possible-JQobzUqaR4U.f251.webm
    [download] 100% of 2.22MiB in 00:01
    [ffmpeg] Merging formats into "Quantum computer coding in silicon now possible-JQobzUqaR4U.webm"
    Deleting original file Quantum computer coding in silicon now possible-JQobzUqaR4U.f248.webm (pass -k to keep)
    Deleting original file Quantum computer coding in silicon now possible-JQobzUqaR4U.f251.webm (pass -k to keep)
    [download] Finished downloading playlist: quantum-testing-shorts
    
    $ ls
    Quantum computer coding in silicon now possible-JQobzUqaR4U.webm  
    Symphony of Science - the Quantum World!-DZGINaRUEkU.mp4
    
  8. When we downloaded the playlist, the default option is to delete original files. So, if we want to keep them, we can just provide -k as shown below:
    $ youtube-dl -k https://www.youtube.com/playlist?list=PLZI6KTHH6719oHLU-Sk3ViuIWJ-G7awXP
    [youtube:playlist] PLZI6KTHH6719oHLU-Sk3ViuIWJ-G7awXP: Downloading webpage
    [download] Downloading playlist: quantum-testing-shorts
    [youtube:playlist] playlist quantum-testing-shorts: Downloading 2 videos
    [download] Downloading video 1 of 2
    [youtube] DZGINaRUEkU: Downloading webpage
    [youtube] DZGINaRUEkU: Downloading video info webpage
    [youtube] DZGINaRUEkU: Extracting video information
    [youtube] DZGINaRUEkU: Downloading DASH manifest
    [youtube] DZGINaRUEkU: Downloading DASH manifest
    [download] Destination: Symphony of Science - the Quantum World!-DZGINaRUEkU.f136.mp4
    [download] 100% of 42.40MiB in 00:22
    [download] Destination: Symphony of Science - the Quantum World!-DZGINaRUEkU.f141.m4a
    [download] 100% of 6.33MiB in 00:03
    [ffmpeg] Merging formats into "Symphony of Science - the Quantum World!-DZGINaRUEkU.mp4"
    [download] Downloading video 2 of 2
    [youtube] JQobzUqaR4U: Downloading webpage
    [youtube] JQobzUqaR4U: Downloading video info webpage
    [youtube] JQobzUqaR4U: Extracting video information
    [youtube] JQobzUqaR4U: Downloading DASH manifest
    [youtube] JQobzUqaR4U: Downloading DASH manifest
    [download] Destination: Quantum computer coding in silicon now possible-JQobzUqaR4U.f248.webm
    [download] 100% of 17.37MiB in 00:09
    [download] Destination: Quantum computer coding in silicon now possible-JQobzUqaR4U.f251.webm
    [download] 100% of 2.22MiB in 00:01
    [ffmpeg] Merging formats into "Quantum computer coding in silicon now possible-JQobzUqaR4U.webm"
    [download] Finished downloading playlist: quantum-testing-shorts
    k@laptop:~/YouTube/1$ ls
    Quantum computer coding in silicon now possible-JQobzUqaR4U.f248.webm
    Quantum computer coding in silicon now possible-JQobzUqaR4U.f251.webm
    Quantum computer coding in silicon now possible-JQobzUqaR4U.webm
    Symphony of Science - the Quantum World!-DZGINaRUEkU.f136.mp4
    Symphony of Science - the Quantum World!-DZGINaRUEkU.f141.m4a
    Symphony of Science - the Quantum World!-DZGINaRUEkU.mp4
    
    $ ls
    $ ls
    Quantum computer coding in silicon now possible-JQobzUqaR4U.f248.webm
    Quantum computer coding in silicon now possible-JQobzUqaR4U.f251.webm
    Quantum computer coding in silicon now possible-JQobzUqaR4U.webm
    Symphony of Science - the Quantum World!-DZGINaRUEkU.f136.mp4
    Symphony of Science - the Quantum World!-DZGINaRUEkU.f141.m4a
    Symphony of Science - the Quantum World!-DZGINaRUEkU.mp4
    
    
  9. We can download a video from Vimeo as well:
    $ youtube-dl https://vimeo.com/22439234
    [vimeo] 22439234: Downloading webpage
    [vimeo] 22439234: Extracting information
    [vimeo] 22439234: Downloading webpage
    [vimeo] 22439234: Downloading JSON metadata
    [vimeo] 22439234: Downloading m3u8 information
    [download] Destination: The Mountain-22439234.mp4
    [download] 100% of 59.93MiB in 01:23