Created
August 22, 2024 04:08
-
-
Save mcthomas/f51f7235baae83daa7ce53f49f6cf635 to your computer and use it in GitHub Desktop.
Search for and play YouTube videos from your terminal. Requires ddgr and mpv.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yt (){ | |
#!/bin/sh | |
if [ $1 = "q" ]; then | |
return | |
fi | |
query="'$*'" | |
isFound=0 | |
url="" | |
output="$(ddgr -x --np --unsafe site:youtube.com/watch $query)\n" | |
clear | |
echo "$output" | |
echo -ne "Input # or search term (q to quit): " | |
read term | |
echo "$output" | while read line || [[ -n $line ]]; | |
do | |
if [ $isFound -eq 1 ]; then | |
url=$line | |
break | |
fi | |
if [[ $line == *$term". "* ]]; then | |
isFound=1 | |
fi | |
done | |
if [ $isFound = 0 ]; then | |
yt $term | |
else | |
mpv $url | |
yt $query | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment