Skip to content

CLI Video Downloader Setup Guide

I found myself in a situation where I wanted to save a video for offline viewing but there was not a native solution to download the video available.

Luckily for me and others, there is an online utility called, YT-DLP. This can be found here on their GitHub: https://github.com/yt-dlp/yt-dlp.

Here are the steps I took to accomplish this:

  1. Create an environment to run this configuration. For me, I created a DigitalOcean virtual server where I spun up an Ubuntu installation and notated the login credentials (SSH and/or root password). For my configuration, I added a storage volume as a data drive to avoid using the main drive.
  2. Install system updates:
    sudo apt update && sudo apt full-upgrade -y
  3. Install necessary packages (ffmpeg, Node.js, Unzip, Deno):
    sudo apt update && sudo apt install -y ffmpeg curl unzip #ffmpeg, Unzip
    curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash – && sudo apt install -y nodejs #Node.js
    curl -fsSL https://deno.land/install.sh | sh #Deno
  4. Install yt-dlp:
    sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
  5. Set permissions for yt-dlp
    sudo chmod a+rx /usr/local/bin/yt-dlp
  6. Check yt-dlp version:
    yt-dlp –version
  7. Extract YouTube cookies from your browser and save them to a file named “cookies.txt” in the same directory as yt-dlp. Note that you might have to redo this step from time to time. Playing a YT video first for 10-15 seconds then closing that tab before doing robots.txt step has been suggested. You can use the following guide for extracting cookies: https://github.com/yt-dlp/yt-dlp/wiki/Extractors#exporting-youtube-cookies
  8. Transfer the “cookies.txt” file to the yt-dlp server from your local system using FileZilla or in the terminal using your preferred method
  9. If your server does not have many resources available (in my case, I used the cheapest plan available at DigitalOcean), you might need to setup a swap file to increase the available memory using these steps:
    sudo fallocate -l 2G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    echo ‘/swapfile none swap sw 0 0’ | sudo tee -a /etc/fstab #Make the swap file permanent
  10. Download a video using yt-dlp with the cookies file:
    yt-dlp –merge-output-format mkv -4 –cookies “/tmp/cookies.txt” “https://www.youtube.com/watch?v=a1B2c3d4E5F” -P “/mnt/volume_xyz_9876543210”
  11. Download a playlist using yt-dlp with the cookies file (use -I to specify which videos from the playlist):
    yt-dlp –merge-output-format mkv -4 –cookies “/tmp/cookies.txt” “https://www.youtube.com/watch?v=a1B2c3d4E5F” -P “/mnt/volume_xyz_9876543210”

Leave a Reply

Your email address will not be published. Required fields are marked *