diff options
author | lucashemi <lucasxberger@gmail.com> | 2022-12-05 10:32:42 -0300 |
---|---|---|
committer | lucashemi <lucasxberger@gmail.com> | 2022-12-05 10:32:42 -0300 |
commit | 970f9bbf67965e1633210be0a3f4dac6daf3c87b (patch) | |
tree | f0e64e769227b3c5826f06f0291a2f547fda14c0 /yts |
First Commit
Diffstat (limited to 'yts')
-rwxr-xr-x | yts | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -0,0 +1,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 |