Initial version
This commit is contained in:
commit
85a0115e9f
13
youtube-cli/README.md
Normal file
13
youtube-cli/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# youtube-cli
|
||||
|
||||
Commandline youtube search tool.
|
||||
|
||||
# Prerequisites
|
||||
|
||||
* jq
|
||||
* yt-dlp
|
||||
* firefox / something (change script if needed)
|
||||
|
||||
# Usage
|
||||
|
||||
./youtube-cli.sh <your search expression>
|
36
youtube-cli/youtube-cli.sh
Executable file
36
youtube-cli/youtube-cli.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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
|
||||
firefox-developer-edition ${youtube_urls[$i - 1]}
|
||||
fi
|
||||
|
||||
rm "$tempfile"
|
||||
else
|
||||
echo 'Usage: ./youtube-cli.sh <your search expression>'
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user