summaryrefslogtreecommitdiff
path: root/yts
blob: d1168cca6c4feddecaf133dbd8e525d0b0a6dc4f (plain)
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
#!/bin/bash

query=$(echo $* | sed s/\ /+/g)
file=$(mktemp)
$(curl -sL "www.youtube.com/results?search_query=${query}" >> ${file})
watches=($(cat ${file} | grep -Po '"videoRenderer":{"videoId":"([a-zA-Z0-9_-]{11})' | awk -F: '{print $3}' | sed 's/^.//' | uniq | awk '{print "www.youtube.com/watch?v="$0}' | head -n5))
titles=$(cat ${file} | grep -Po '"title":{"runs":\[{"text":.{1,100}"}\],' | awk -F: '{print $4}' | sed 's/....$//' | sed 's/.//' | head -n5)
rm ${file}
for ((i=0;i<5;i++))
do
    title[i]=$(echo "${titles}" | head -n$(echo "${i}+1" | bc)  | tail -n1)
done
lines=()
space=" | "
for ((i=0;i<${#watches[@]};i++))
do 
    lines+=${watches[i]}${space}${title[i]}$'\n'
done
url=$(echo "${lines[*]}" | dmenu -i -l 5)
if [ -z "${url}" ]
then
    echo "Error: No video selected!"
else
    ${BROWSER} $(echo "${url}" | grep -Po '^.{35}')
fi