YouTube Download Server
| 13 (trixie) | This includes a lightweight LXC
|
| As always... | |
|---|---|
|
Start with: |
|
There are a few good reasons to be set up to download YouTube videos.
- Geofencing
- Reliability
- Bandwidth Management
Fortunately, it's pretty easy to do.
yt-dlp (formerly youtube-dl)
yt-dlp is a pretty awesome tool.
As an added bonus, it also works with a fairly large number of other video sharing sites...
Note: You'll need ffmpeg...
sudo apt install ffmpeg
But don't install it through the package manager. It gets incredibly regular updates & the package manager kinda borks this.
Instead, install it directly:
sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux -O /usr/local/bin/yt-dlpsudo chmod a+rx /usr/local/bin/yt-dlp
This allows you to regularly update (maybe even through cron) it with the command:
sudo yt-dlp -U
Which guarantees you keep up with the multitude of random changes made at YouTube.
Storage
Storage space for downloading (Torrents & such) should be done on a dedicated drive.
I tend to do most of my storage via NFS served up by my dedicated storage server.
Create a DONE & a WIP folder on the storage drive. This will make it easier to keep things organised.
sudo mkdir /mnt/Download_Spacesudo vi /etc/fstab
StorageServer:/Download_Space /mnt/Download_Space nfs rw,user,exec 0 0
sudo mkdir /mnt/Download_Space/YTDL
If you don't want to use an NFS share for this, you could either add a dedicated drive or just set up the folders on the boot drive. I'd seriously recommend, at minimum, 500GB of available space.
Useful things
Configure your download server to use a good VPN.
also:
sudo apt install mosquitto-clients
Handy for integrating the download server into your IoT infrastructure...
Usage hints
You can either sign into the machine to download videos, or (especially if you've set up for passwordless SSH) just do it from your desktop.
If you're signed in
yt_dlp -P "/mnt/Download_Space/YTDL/" URLofVideoPage
Where:
/mnt/Download_Space/YTDL/ Can be any location on that server that you have write access to. Leaving off the -P "/mnt/Download_Space/YTDL/" will download to where ever you are...
URLofVideoPage is simply the URL of the YouTube video (i.e: https://www.youtube.com/watch?v=NkXLP3VtMS8 )
Simple as that, it'll download the video in approximately the best available resolution.
Take a look at yt-dlp --help or visit their instructions online to learn all about possible options.
Remote usage
ssh DLSERVER yt_dlp -P "/mnt/Download_Space/YTDL/" URLofVideoPage
Where:
DLSERVER is the name or IP of your download server.
/mnt/Download_Space/YTDL/ Can be any location on that server that you have write access to.
URLofVideoPage is the URL of the YouTube video (i.e: https://www.youtube.com/shorts/c4OdhYWV4Rk )
Scripting
Example of a useful script to update a local copy of a YouTube Channel:
yt-dlp -w --download-archive 11111111-ARCHIVE --write-description -t mp4 -o "%(upload_date)s - %(title)s.%(ext)s" https://www.youtube.com/user/LastWeekTonight
This particular little script maintains a local archive of a channel that YouTube thinks Canadians should not be allowed to watch... (needless to say, it gets run on the VPN equipped Download Server.)
Tips
If you see this error:
ERROR: [youtube] My7MhdGjLzo: Sign in to confirm you’re not a bot. Use --cookies-from-browser or --cookies for the authentication. See https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp for how to manually pass cookies. Also see https://github.com/yt-dlp/yt-dlp/wiki/Extractors#exporting-youtube-cookies for tips on effectively exporting YouTube cookies
Chances are very good that YouTube hates your VPN exit point.
In my case, they seem to dislike Sweden.
Changing to Ukraine solved the issue... ¯\_(ツ)_/¯
Also... Sidequest... Desktop YT downloading
YoutubeDownloader (Desktop downloader)
Quite functional as long as you don't mind a purely GUI application that can't remember where you really want it to put the files.
Doesn't seem to have any sort of installer...
Just hunt through the folder for the actual application in yer file explorer & double-click it.
It works & isn't particularly hard to use...
For a GUI app, the UI is incrediply limited, but functional enough to get the job done.