dotfiles

My collection of dotfiles
git clone git://git.noxz.tech/dotfiles
Log | Files | Refs

dmenu_yt_search (1866B)


      1 #!/bin/sh
      2 
      3 args=" -i -l 20 -p ▶ -sb #ca0200 -sf #ffffff -nb #000000 -nf #ffffff"
      4 search_phrase="$(echo -n | dmenu_vtc${args}                                 \
      5 	| sed 's/\ /+/g'                                                        \
      6 	| hexdump -v -e '/1 "%02x"'                                             \
      7 	| sed 's/\(..\)/%\1/g')"
      8 [ "$search_phrase" = "" ] && exit 1
      9 
     10 search_results="$(curl 2>/dev/null                                          \
     11 	"https://www.youtube.com/results?search_query=$search_phrase"           \
     12 	| sed 's/<a /\n<a /g')"
     13 search_data="$(echo $search_results                                         \
     14 	| grep -o '<a href=\"/watch?v=[^>]*>'                                   \
     15 	| grep -v 'list='                                                       \
     16 	| sed -r "s/^<a(.*?)href=\"\/watch\?v=([^\"]+)\"(.*?)title=\"([^\"]+)\"(.*?)>/\2;\4/")"
     17 time=""
     18 line=""
     19 data=""
     20 options=""
     21 nr=""
     22 i="0"
     23 id=""
     24 name=""
     25 
     26 [ "$search_data" = "" ] && exit 0
     27 
     28 while :; do
     29 	line="${search_data%%
     30 *}"
     31 	i="$((i+1))"
     32 	nr="$(printf "%02d" "$i")"
     33 	id="${line%%;*}"
     34 	name="${line#*;}"
     35 	data="$data$nr $id\n"
     36 	time="$(echo "$search_results" | grep -B 1 -- "$id" 2>/dev/null \
     37 		| grep "video-time" 2>/dev/null                                     \
     38 		| sed -r "s/<span[^>]*>([^<]*).*/\1/")"
     39 
     40 	if [ "$time" = "" ]; then
     41 		time="LIVE!"
     42 	elif [ "$(echo "$time" | grep -o ':' | wc -l)" != "2" ]; then
     43 		time="$(date --date="00:$time" +"%M:%S")"
     44 	else
     45 		time="$(date --date="$time" +"%H:%M:%S")"
     46 	fi
     47 
     48 	options="$options$nr [$time] "$(echo "$name" | recode html..unicode)"\n"
     49 	search_data="${search_data#*
     50 }"
     51 	if [ "$line" = "$search_data" ]; then break; fi
     52 done
     53 
     54 choice="$(echo $options | sed '/^\s*$/d' | sort | dmenu_vtc${args})"
     55 
     56 [ "$choice" = "" ] && exit 1
     57 
     58 choice="$(printf "$data" | grep ^${choice%% *})"
     59 dmenu_url_open "https://www.youtube.com/watch?v=${choice#* }"