From 970f9bbf67965e1633210be0a3f4dac6daf3c87b Mon Sep 17 00:00:00 2001 From: lucashemi Date: Mon, 5 Dec 2022 10:32:42 -0300 Subject: First Commit --- yts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 yts diff --git a/yts b/yts new file mode 100755 index 0000000..d1168cc --- /dev/null +++ b/yts @@ -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 -- cgit v1.2.3-18-g5258