#!/bin/sh if [ -z "$1" ] then rm -rf ~/.cache/webgut/thumbnails/* rm ~/.cache/webgut/list & touch ~/.cache/webgut/list & echo "What do you want to search?" && read resp query=$(echo $resp | gsed 's/ /+/g') && curl -s https://y.com.sb/api/v1/search?q="$query" \ | gsed 's/,"/\n"/g' \ | gsed 's/^\s//g' \ | gsed 's/^[A-Za-z].*$//g' \ | grep -e "title" -e "/maxres.jpg" -e "videoId" \ | gsed ':a; N; s/\n/ /; ta' \ | gsed 's/\s"title/\n"title/g' \ | gsed 's/"[A-Za-z]*":"//g' \ | gsed 's/"/***/g' \ | gsed 's/ /_/g' \ | gsed 's/\*\*_/\*\*/g' \ >>~/.cache/webgut/list sp='/-\|' for line in $(cat ~/.cache/webgut/list) do name=$(echo $line | gawk -F '***' '{print($1)}') thumbnail=$(echo $line | gawk -F '***' '{print($3)}') curl -s --create-dirs --output ~/.cache/webgut/thumbnails/$(echo $name | sed 's/\//\ /g').jpg $thumbnail & done && printf 'Starting image download.\n' printf ' Loading images' & while [ $(ls ~/.cache/webgut/thumbnails | wc -l) -le 22 ]; do printf '\r\b %.1s' "$sp" sp=${sp#?}${sp%???} sleep 0.1 done && nsxiv -t ~/.cache/webgut/thumbnails/* else videoId=$(cat ~/.cache/webgut/list | grep $1 | gawk -F '***' '{print($2)}') videoUrl=https://yewtu.be/watch/?v=$videoId printf "$1***$videoUrl \n" >> ~/.cache/view_hist & mpv $videoUrl fi