Bash (or your shell of choice) aliases.
To get your video with max quality, subtitles or youtube auto-subs, and the uploader's name prepending the filename:
alias vidget='youtube-dl -o "/YOUR/DIRECTORY/HERE/%(uploader)s - %(title)s-%(id)s.%(ext)s" --prefer-ffmpeg --write-sub --sub-lang=en --write-auto-sub --sub-format best --embed-subs'
To do the same as the above, but get every video in a playlist labelled in order in your current directory.
alias youtube-dl-ordered='youtube-dl -o "%(playlist_index)s-%(uploader)s - %(title)s-%(id)s.%(ext)s" --prefer-ffmpeg --write-sub --sub-lang=en --write-auto-sub --sub-format best --embed-subs'
A script to quickly execute streamlink for your link in a terminal:
Bash:
#!/bin/bash
set -e -o pipefail
DIR="/YOUR/DIRECTORY/HERE/"
#Define your folder to save in above.
streamlink --hls-live-edge 99999 --hls-segment-threads 5 --hls-live-restart -o "$DIR/$(date +%Y-%m-%d-%R).mp4" "$1" best
exit
A script that you can run every minute via
cron to continuously monitor for a livestream and start downloading it as soon as it starts. Note that youtube likes to lie about when people are live and even display old content as "live", clogging up whatever storage you use.
Bash:
#!/bin/bash
set -e -o pipefail
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/user/Scripts:/home/user/.local/bin/
#Had to set this because youtube-dl was in an unusual place for execution, likely due to pip installation.
NAME="MadattheInternet"
#channel id goes above
if [ $(ps aux | grep "$NAME" | grep youtube-dl | wc -l) -le 0 ]
then
echo "No process, commencing download..."
youtube-dl -o "/YOUR/DIRECTORY/HERE/%(uploader)s - %(title)s-%(id)s.%(ext)s" --prefer-ffmpeg --write-sub --sub-lang=en --write-auto-sub --sub-format best --embed-subs --cookies="/YOUR/DIRECTORY/HERE/youtube-dl-cookies.txt" "https://www.youtube.com/c/$NAME/live"
else
echo "Download underway, skipping execution..."
#This is to deduplicate downloads, otherwise your folder will get filled with duplicate streams and your bandwidth will eventually be filled.
fi
#Note that some channels use "channel/ID" instead of "c/ID". Before adapting this script to your target, check this first.
#Also you can use just "$NAME" on the youtube-dl line and have this work with any youtube-dl compatible link in the NAME field.
exit
For this zoomer Trovo platform, there's an extra step. You MUST use streamlink, and put
this custom extractor into your
~/.config/streamlink/plugins folder, creating it if it doesn't exist. The following is the same auto-loader (as managed by cron) above, with
streamlink as the runner program and Trovo set in there as an example. This would likely also work well for Twitch channels.
Bash:
#!/bin/bash
set -e -o pipefail
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/user/Scripts:/home/user/.local/bin/
DIR="/YOUR/DIRECTORY/HERE"
NAME="https://trovo.live/StillMad"
#channel URL goes above
if [ $(ps aux | grep "$NAME" | grep streamlink | wc -l) -le 0 ]
then
echo "No process, commencing download..."
streamlink --hls-live-edge 99999 --hls-segment-threads 5 --hls-live-restart -o "$DIR/Kiwi Farms - $(date +%Y-%m-%d-%R).mp4" "$NAME" best
#Note that we are setting the uploader name "Kiwi Farms" manually. Streamlink to my knowledge does not have features for extracting usernames.
else
echo "Download underway, skipping execution..."
fi
exit
To do the monitoring scripts above once every minute, I use
crontab -e to add lines like
* * * * * /YOUR/SCRIPT/DIRECTORY/trovo/josh
Youtube may start giving you "429: Too Many Requests" for doing this. There's a
process you can do to get your cookies that's a little complicated, but I think it's worth your time to be able to save any livestream ever that a person you're interested in does.
Does one of these programs inexplicably stop working? Don't forget to use
pip install --user --upgrade <program> from time to time.