I don’t use this anymore, got sick of streaming and buffering.
I use this now:
#!/bin/bash
# Directory for downloaded videos:
DL_DIR="$HOME/Videos/temp"
# Video player:
PLAYER="xdg-open"
#PLAYER="/usr/bin/mpv"
#PLAYER="/usr/bin/smplayer"
# Downloader and options:
YTDL="$HOME/bin/yt-dlp"
YTDL_OPTS=(--no-playlist --throttled-rate=100000 -N 10)
YTDL_DIR_OPTS=(-P "$DL_DIR")
set -e
CMD() {
printf "[CMD]: "
printf "\"%s\" " "$@"
printf "\n"
"$@"
}
# Get URL from clipboard if run without argument:
if [ -z "$1" ]; then
URL="$(xclip -o -sel c)"
CLEAR_CLIPBOARD=1
else
URL="$1"
fi
# Get video filename
printf "[URL]: %s\n" "$URL"
FILENAME=$("$YTDL" --get-filename "${YTDL_DIR_OPTS[@]}" "$URL")
printf "[FILE]: %s\n" "$FILENAME"
# Download video
CMD "$YTDL" "${YTDL_OPTS[@]}" "${YTDL_DIR_OPTS[@]}" "$URL"
# Play video
CMD "$PLAYER" "$FILENAME" >/dev/null 2>&1
# OPTIONAL clear clipboard (KDE only)
if (($CLEAR_CLIPBOARD)); then
CMD qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory
fi
To use it, I just copy the URL to the clipboard, and run the script above (I have a keybinding Meta+V for it).
Every video that I watch gets saved in $HOME/Videos/temp
directory. I manually wipe it clean every couple of days. You can easily change the script to save videos to /tmp
, so that they get removed automatically on reboot, but I like to keep them, storage is cheap.
A comment about this line:
YTDL="$HOME/bin/yt-dlp"
I don’t use yt-dlp
from the repos, I simply cloned the master branch from the official git repo somewhere in my home directory and then symlinked the executable to $HOME/bin/yt-dlp
. This is because yt-dlp
often gets broken (scumbags at YouTube often intentionally change their API to break it), and I don’t like to wait until it gets updated in the repos (Arch is simply not enough bleeding edge for me ). So I just manually run git pull
to update it when it breaks.