#!/bin/sh while getopts "s:v:S:V" flag do case $flag in s) use=sound && link=$OPTARG ;; v) use=video && link=$OPTARG;; S) use=batch_sound ;; V) use=batch_video ;; esac done vidselect() { :> ~/.cache/vid_sload/list && dl_links=$(cat ~/.cache/dl_list | gsed 's/https.*v=//g' | gsed -z 's/\n/\|/g' | sed 's/\|$//g') && num=1 for line in $(cat ~/.cache/view_hist) do (echo "$line" | grep -q -E $dl_links && printf '[X] %s\n' "$line" || printf '[%s] %s\n' "$num" "$line") >> ~/.cache/vid_sload/list num=$((( $num+1 ))) done && cat ~/.cache/vid_sload/list && echo "####################################" && echo "Add video to list (a), download (s/v/l) or exit?" && read ans; mode=$(echo $ans | gsed 's/\s.*//g') && argnam=$(echo $ans | sed 's/^.//g') && vidlink=$(grep $argnam ~/.cache/vid_sload/list | gsed 's/^.*\]\s//' | gsed 's/^.*\*\*\*//g') cd ~/Downloads if [ $mode == 'a' ]; then echo $vidlink >> ~/.cache/dl_list echo $vidlink reload elif [ $mode == 's' ]; then yt-dlp -x -w -c --embed-chapters --prefer-free-formats $vidlink && exit elif [ $mode == 'v' ]; then yt-dlp -f 'bestvideo[height<=480]+bestaudio/best[height<=360]/best[height<=720]/best' -w -c --embed-chapters --prefer-free-formats $vidlink && exit elif [ $mode == 'l' ] ; then yt-dlp -f 'bestvideo[height<=480]+bestaudio/best[height<=360]/best[height<=720]/best' -w -c --embed-chapters --prefer-free-formats -a ~/.cache/dl_list && rm ~/.cache/dl_list && touch ~/.cache/dl_list && exit elif [ $mode == 'exit' ] ; then exit else echo "Unknown option: Please try again." fi } reload() { clear vidselect } if [ -z "$1" ] then vidselect else cd ~/Downloads case $use in sound) yt-dlp -x -w -c --embed-chapters --prefer-free-formats $link && exit;; video) yt-dlp -f 'bestvideo[height<=480]+bestaudio/best[height<=360]/best[height<=720]/best' -w -c --embed-chapters --prefer-free-formats $link && exit;; batch_sound) yt-dlp -x -w -c --prefer-free-formats -a ~/.cache/dl_list && rm ~/.cache/dl_list && touch ~/.cache/dl_list && exit ;; batch_video) yt-dlp -f 'bestvideo[height<=480]+bestaudio/best[height<=360]/best[height<=720]/best' -w -c --embed-chapters --prefer-free-formats -a ~/.cache/dl_list && rm ~/.cache/dl_list && touch ~/.cache/dl_list && exit ;; esac fi