37 lines
823 B
Bash
Executable File
37 lines
823 B
Bash
Executable File
#!/bin/bash
|
|
|
|
if [ "$#" -gt 0 ]; then
|
|
echo "Searching youtube for: $*..."
|
|
|
|
tempfile=$(mktemp)
|
|
|
|
yt-dlp -j "ytsearch5:$*" 2> /dev/null > $tempfile
|
|
|
|
# See: https://mywiki.wooledge.org/BashFAQ/005
|
|
# For alternatives (read file line-by-line), see: https://mywiki.wooledge.org/BashFAQ/001
|
|
mapfile -t youtube_urls < <(cat $tempfile | jq '.webpage_url' | tr -d '"' )
|
|
|
|
mapfile -t choices < <(cat $tempfile | jq '.fulltitle, .webpage_url')
|
|
for i in "${!choices[@]}"; do
|
|
let m=i%2
|
|
if [ $m -eq 0 ]; then
|
|
let j=i/2+1
|
|
echo "$j: ${choices[$i]}"
|
|
else
|
|
echo " ${choices[$i]}"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "Enter video index to run:"
|
|
read i
|
|
if [ -n $i ]; then
|
|
# you can dou whatever like'em pee-vee
|
|
mpv ${youtube_urls[$i - 1]}
|
|
fi
|
|
|
|
rm "$tempfile"
|
|
else
|
|
echo 'Usage: ./youtube-cli.sh <your search expression>'
|
|
fi
|