youtube-cli/youtube-cli.sh

37 lines
823 B
Bash
Raw Normal View History

2024-09-15 22:03:06 +02:00
#!/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
2024-09-15 22:08:20 +02:00
mpv ${youtube_urls[$i - 1]}
2024-09-15 22:03:06 +02:00
fi
rm "$tempfile"
else
echo 'Usage: ./youtube-cli.sh <your search expression>'
fi