-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyt
executable file
·32 lines (24 loc) · 855 Bytes
/
yt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /bin/sh
YT_FILTER_FILE=~/scripts/personal/ytfilters
if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ]; then
printf "$ yt <query>
Play the first video for the given query in mpv
Example:
$ yt samurai champloo
#=> plays first episode of samurai champloo
"; exit
fi
QUERY="$(echo $@)"
[ -z "$1" ] && QUERY="$(rofi -dmenu -l 0 -width 35 -p yt)"
[ -z "$QUERY" ] && exit 1
if [ -e "$YT_FILTER_FILE" ]; then
if echo "$QUERY" | grep -if $YT_FILTER_FILE >/dev/null; then
rofi -e "Prohibited query" -width 35
exit 2
fi
fi
QUERY=$(node -e "console.log( encodeURIComponent( '$QUERY' ) )")
curl -s "https://www.youtube.com/results?search_query=$QUERY" | \
grep -Po "/watch\?v=\K.+?\"" | head -n1 | cut -d\" -f1 | \
awk '{ print "https://youtube.com/watch?v="$1 }' | \
xargs -r tsp mpv --fs --profile=overlay 2>/dev/null