yahoo picture search

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-10 15:58:19 +02:00
parent a734b5f5ab
commit e89942074a

View File

@ -2,7 +2,7 @@
# files: mycommands.sh.dist # files: mycommands.sh.dist
# copy to mycommands.sh and add all your commands and functions here ... # copy to mycommands.sh and add all your commands and functions here ...
# #
#### $$VERSION$$ v0.72-dev-6-ga51f8ca #### $$VERSION$$ v0.72-dev-7-ga734b5f
# #
# shellcheck disable=SC2154 # shellcheck disable=SC2154
# shellcheck disable=SC2034 # shellcheck disable=SC2034
@ -65,10 +65,9 @@ else
# Inline query examples # Inline query examples
# shellcheck disable=SC2128 # shellcheck disable=SC2128
case "${iQUERY}" in case "${iQUERY}" in
"google "*) # search in google images "image "*) # search in yahoo images
local search="${iQUERY#* }" local search="${iQUERY#* }"
answer_inline_multi "${iQUERY[ID]}" "$(my_image_search "${search}")" answer_inline_multi "${iQUERY[ID]}" "$(my_image_search "${search}")"
exit
;; ;;
"photo") # manually provide URLs "photo") # manually provide URLs
answer_inline_multi "${iQUERY[ID]}" " answer_inline_multi "${iQUERY[ID]}" "
@ -97,18 +96,21 @@ exit
answer_inline_query "${iQUERY[ID]}" "article" "GitHub" "http://github.com/topkecleon/telegram-bot-bash" answer_inline_query "${iQUERY[ID]}" "article" "GitHub" "http://github.com/topkecleon/telegram-bot-bash"
;; ;;
esac esac
exit
} }
# place your processing functions here # place your processing functions here
# problem: google returns png :-(
# $1 search parameter # $1 search parameter
my_image_search(){ my_image_search(){
local image result sep="" local image result sep="" count="1"
result="$(wget --user-agent 'Mozilla/5.0' -qO - "https://www.google.com/search?q=$1&tbm=isch" | sed 's/</\n</g' | grep '<img')" result="$(wget --user-agent 'Mozilla/5.0' -qO - "https://images.search.yahoo.com/search/images?p=$1" | sed 's/</\n</g' | grep "<img src=")"
while read -r image; do while read -r image; do
image="${image#* src=\"}"; image="${image%%\" width=\"*}" [ "$count" -gt "9" ] && break
image="${image#* src=\'}"; image="${image%%&pid=*}"
[[ "${image}" = *"src="* ]] && continue
echo "${sep}"; inline_query_compose "$RANDOM" "photo" "${image}"; sep="," echo "${sep}"; inline_query_compose "$RANDOM" "photo" "${image}"; sep=","
count=$(( count + 1 ))
done <<<"${result}" done <<<"${result}"
} }