Introduction
Introduction Statistics Contact Development Disclaimer Help
image-search - annna - Annna the nice friendly bot.
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6…
Log
Files
Refs
Tags
README
---
image-search (903B)
---
1 #!/bin/sh
2
3 searxbase="https://baresearch.org"
4 maxtries=10
5
6 die() {
7 printf '%s: error: %s\n' "${0%%*/}" "$1"
8 exit "${2:-1}"
9 }
10
11 get_image() {
12 q="$(printf '%s' "$1" | sed 's/ /%20/g')"
13 s="$(printf '%s' "$1" | sed 's/ /_/g')"
14 searxuri="${searxbase}/search?q=${q}&categories=images"
15 curl -s "${searxuri}" \
16 | xml2tsv 2>/dev/null \
17 | grep img \
18 | cut -f 2 \
19 | grep ^src \
20 | cut -d'=' -f 2- \
21 | while read -r uri;
22 do
23 case "${uri}" in
24 /*)
25 uri="${searxbase}${uri}"
26 ;;
27 esac
28
29 out="${s}.jpg"
30 if curl -s "${uri}" -o "$out"
31 then
32 printf '%s\n' "$out"
33 case "$(file -ib "$out")" in
34 image/jpeg)
35 return
36 ;;
37 image/*)
38 magick convert "$out" "${out}.tmp.jpg"
39 mv "${out}.tmp.jpg" "$out"
40 return
41 ;;
42 esac
43 fi
44
45 if test "$i" -gt 0
46 then
47 sleep 1
48 fi
49 i=$((i + 1))
50 done
51 }
52
53 if test $# -lt 1
54 then
55 exit 0
56 fi
57
58 i=0
59 for q in "$@"
60 do
61 get_image "$q"
62 done
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.