summaryrefslogtreecommitdiff
path: root/webgut
blob: ba2a1956f827ca63f317f1a2466b8327d5ba8509 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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