Min Soe Han

yt-dlp notes

2023-03-12 Sunday 15:18 03:18:36 PM

Recently I uninstall youtube-dl and install yt-dlp.

I was surprised when I look at yt-dlp (1) man page. There are many options and options of options. In fact, I just need to download video or audio file with quality as good as possible. I don’t really care this and that. So, I created the following script.

#!/bin/dash

durl=$(wl-paste)
ckyt=$(echo "$durl" | awk -F '/' '{print $3}')
if [ "$ckyt" = "www.youtube.com" ]; then
    fmli=$(yt-dlp -F "$durl" | grep 'mp3\|mp4\|m4a\|webm\|3gp' | wofi -d)
    fmsl=$(yt-dlp -F "$durl" | grep 'mp3\|mp4\|m4a\|webm\|3gp' | grep "$fmli")

    if [ ! -z "$fmli" ] && [ ! -z "$fmsl" ]; then
        fmid=$(echo "$fmsl" | cut -d ' ' -f 1)
        alacritty -t "terminal-float" -e yt-dlp -f "$fmid" "$durl"
    else
        notify-send -t 1800 " " "clean exit\n_"
    fi
else
    notify-send -t 1800 " " "the link is not YouTube link. Fuck You!\n_"
    exit 0
fi

The script need wofi or fuzzel or bemenu, and a terminal like alacritty. Then put it in the $PATH and execute it.