How to preserve audio

Prerequisites

  1.  Download yt-dlp with the package manager of your choice. Examples: 
    sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp
    sudo chmod a+rx /usr/local/bin/yt-dlp
    
    python3 -m pip install -U yt-dlp
    
    yay yt-dlp
    
    sudo apt install yt-dlp
    
    sudo nala install yt-dlp
  2. Download ffmpg with the package manager of your choice. Examples:
    yay ffmpeg
    
    sudo apt install ffmpeg
    
    sudo nala install ffmpeg
  3. Download optional dependencies if necessary from here
  4. Make a directory where your config files will sit
  5. Create your first config. Example:
    # Uses best audio
    -f bestaudio
    
    # Don't stop even if not perfect
    -ciw
    
    # verbose
    -v
    
    # Extracts the audio
    --extract-audio
    
    # Uses best quality
    --audio-quality 0
    
    # Makes it a mp3
    --audio-format mp3
    
    # Thumbnail
    --write-thumbnail
    --embed-thumbnail
    
    # Embed info json
    --write-info-json
    --embed-info-json
    
    # Metadata
    --embed-metadata
    
    # Description
    --write-description
    
    # Mark Video as watched. May count towards view count.
    --mark-watched
  6. More file examples can be found here

Time to archive

How to archive an entire YouTube channel


  1. Create a directory where you want your files to be
  2. Download or create the necessary files to create directories, move files and download videos. Examples:
    #!/bin/sh
    
    if [ ! -d "audio" ] ; then
    mkdir audio && mkdir metadata && mkdir thumbnails && mkdir descriptions && echo "Created directories"
    fi
    #!/bin/bash
    
    if compgen -G "*.mp3" > /dev/null ; then
    mv *.mp3 audio/ && mv *.webp thumbnails/ && mv *.description descriptions/ && mv *.info.json metadata/ && echo "Moved files"
    fi
    #!/bin/bash
    yt-dlp --config-location /srv/dev-disk-by-uuid-fa1e36be-9ccc-4549-8734-fe6117b30317/croni/andre/andre/Archive/yt-dlp/yt-dlp_music.conf --download-archive youtube_backup_downloaded.txt --yes-playlist 'https://youtube.com/playlist?list=PLeEbifL6wH9okMEgTQP459RcTrjBWkF_b'
  3. Execute these files however you want. I personally would recommend to set up a cron job to periodically download new videos. Example:
    nohup ./backup.sh > backup.log &


  4. If you execute the command above your only way to know what yt-dlp is currently doing is to tail the log with tail -f backup.log

  5.  While waiting for the download to finish you can create the necessary directories to organize all your downloaded files. Example:
    #!/bin/sh
    
    if [ ! -d "audio" ] ; then
    mkdir audio && mkdir metadata && mkdir thumbnails && mkdir descriptions && echo "Created directories"
    fi

  6. When the download is finished an you created the directories it is time to move them to their dedicated directory. Example:
    #!/bin/bash
    
    if compgen -G "*.mp3" > /dev/null ; then
    mv *.mkv audio/ && mv *.webp thumbnails/ && mv *.description descriptions/ && mv *.info.json metadata/ && echo "Moved files"
    fi
  7. You successfully archived an entire YouTube channel 🚀


Tips