yt-dlp
How to use yt-dlp to preserve video and audio

How to preserve videos

Prerequisites
 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 
 
 Download ffmpg with the package manager of your choice. Examples:
 yay ffmpeg

sudo apt install ffmpeg

sudo nala install ffmpeg 
 
 Download optional dependencies if necessary from here 
 Make a directory where your config files will sit 
 Create your first config. Example:
 # best video and audio
-f bestvideo+bestaudio 

# Just go on even if everything burns
-ciw 

# verbose
-v

# Thumbnail
--write-thumbnail
--embed-thumbnail

# Add chapters
--embed-chapters

# Embed info json
--write-info-json
--embed-info-json 

# Metadata
--embed-metadata

# Description
--write-description

# Comments
#--write-comments

# Mark Video as watched. May count towards view count.
--mark-watched

# Merge downloaded video and audio into a mkv file
--merge-output-format mkv 
 
 More file examples can be found here

Time to archive
How to archive an entire YouTube channel 
 
 
 Create a directory where you want your files to be 
 Download or create the necessary files to create directories, move files and download videos. Examples:
 #!/bin/sh

if [ ! -d "video" ] ; then
mkdir video && mkdir metadata && mkdir thumbnails && mkdir descriptions && echo "Created directories"
fi 
 #!/bin/bash

if compgen -G "*.mkv" > /dev/null ; then
mv *.mkv video/ && 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_video.conf --download-archive youtube_backup_downloaded.txt --yes-playlist 'https://youtube.com/playlist?list=PLeEbifL6wH9okMEgTQP459RcTrjBWkF_b' 
 
 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 & 
   
 
 
 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 
 
  While waiting for the download to finish you can create the necessary directories to organize all your downloaded files. Example:
 #!/bin/sh

if [ ! -d "video" ] ; then
mkdir video && mkdir metadata && mkdir thumbnails && mkdir descriptions && echo "Created directories"
fi 
 
 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 "*.mkv" > /dev/null ; then
mv *.mkv video/ && mv *.webp thumbnails/ && mv *.description descriptions/ && mv *.info.json metadata/ && echo "Moved files"
fi 
 
 You successfully archived an entire YouTube channel 🚀 
 
 
 Tips 
 
 Make your files executable with sudo chmod +x file.sh 
 You can execute the files with ./file.sh 
 This guide can be adapted to download playlist and even single videos 
 
 If you only want to download one video then remove  --yes-playlist

How to preserve audio

Prerequisites
 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 
 
 Download ffmpg with the package manager of your choice. Examples:
 yay ffmpeg

sudo apt install ffmpeg

sudo nala install ffmpeg 
 
 Download optional dependencies if necessary from here 
 Make a directory where your config files will sit 
 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 
 
 More file examples can be found here

Time to archive
How to archive an entire YouTube channel 
 
 
 Create a directory where you want your files to be 
 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' 
 
 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 & 
 
 
 
 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 
 
  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 
 
 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 
 
 You successfully archived an entire YouTube channel 🚀 
 
 
 Tips 
 
 Make your files executable with sudo chmod +x file.sh 
 You can execute the files with ./file.sh 
 This guide can be adapted to download playlist and even single videos 
 
 If you only want to download one video then remove  --yes-playlist