33 lines
738 B
Bash
Executable File
33 lines
738 B
Bash
Executable File
#!/bin/bash
|
|
player="mpv"
|
|
cachedir=~/.cache/play
|
|
mkdir -p "$cachedir"
|
|
touch "$cachedir/query"
|
|
cache="$(grep -F "$1" "$cachedir/query")"
|
|
IFS=$'\1'
|
|
|
|
function yt_search() {
|
|
res=($(yt-dlp ytsearch10:"$1" --flat-playlist -J | jq -r '.entries[] | "\(.title)'$'\01''\(.url)'$'\01''"' | tr -d '\n'))
|
|
|
|
for (( i=0; i<${#res[@]}; i=i+2 )); do
|
|
echo "$(((i+2)/2)). ${res[$i]} ${res[$((num+1))]}"
|
|
done
|
|
|
|
read -p "Meow? " num
|
|
meow="${res[$((num*2+1))]}"
|
|
echo "$meow"'$'\01''"$1" > "$cachedir/query"
|
|
}
|
|
|
|
if [[ "$cache" != '' ]]; then
|
|
read -p "Found search in query cache. Wanna skip querying? [Yn]" yn
|
|
if [[ $yn == "n" ]]; then
|
|
yt_search "$1"
|
|
else
|
|
meow="${cache//$'\01'*}"
|
|
fi
|
|
else
|
|
yt_search "$1"
|
|
fi
|
|
|
|
mpv --ytdl-format="251/250/140" "$meow"
|