
    i                         d Z ddlmZ ddlmZ ddlmZ ddlmZmZm	Z	 dddd	d	d
dZ
ddgZdZdZ	 dZdZddddZd Zd Zy)av  This is the implementation of the Google Images engine using the internal
Google API used by the Google Go Android app.

This internal API offer results in

- JSON (``_fmt:json``)
- Protobuf_ (``_fmt:pb``)
- Protobuf_ compressed? (``_fmt:pc``)
- HTML (``_fmt:html``)
- Protobuf_ encoded in JSON (``_fmt:jspb``).

.. _Protobuf: https://en.wikipedia.org/wiki/Protocol_Buffers
    )	urlencode)loads)fetch_traits)get_google_infotime_range_dictdetect_google_sorryzhttps://images.google.comQ521550z+https://developers.google.com/custom-searchFJSON)websitewikidata_idofficial_api_documentationuse_official_apirequire_api_keyresultsimageswebT2   active)r         c           	         t        |t              }d|d   z   dz   dz   t        | dd|d   ddi      z   d	|d
   dz
   z   }|d   t        v r |dt        ddt        |d      z   i      z   z  }|d   r|dt        dt        |d      i      z   z  }||d<   |d   |d<   |d   j                  |d          d|j                  dd       d|d   d<   |S )zGoogle-Image search requestzhttps://	subdomainz/search?isch)qtbmparamsasearchz&async=_fmt:json,p:1,ijn:pagenor   
time_range&tbszqdr:
safesearchsafeurlcookiesheadersz@NSTN/3.60.474802233.release Dalvik/2.1.0 (Linux; U; Android 12; countryUSz) gzipz
User-Agent)r   traitsr   r   filter_mappingupdateget)queryr   google_info	query_urls       ,/root/searxng/searx/engines/google_images.pyrequestr2   3   sB    "&&1K 	
k
"	#
	 	 %[+h2G[TZ[
\		] &fX&6&:%;
<	=  l.S9eVof\FZ6[-[%\]]]	lS9fnVL=Q.R%STTT	F5M#I.F9
9[34 	Nkoo^gimNnMoouv 9l# M    c           
         g }t        |        | j                  j                  d      }t        | j                  |d       }|d   j	                  dg       D ]  }|d   d   |d   d   |d   d	   |d   d
   |d   d    d|d   d    |d   d   |d   d   dd}|d   j	                  di       j	                  d      }|rdj                  |      |d<   |d   j	                  di       j	                  d      }|r|dxx   d|z   z  cc<   |d   j	                  d      }|r|dxx   d|z   z  cc<   |j	                  di       j	                  d      }	|	r|dxx   d|	z  z  cc<   |j                  |         |S )z)Get response from google's search requestz	{"ischj":Nischjmetadataresultreferrer_url
page_titletext_in_gridsnippet
site_titleoriginal_imagewidthz x heightr%   	thumbnailzimages.html)r%   titlecontentsource
resolutionimg_srcthumbnail_srctemplateiptccreatorz, authorcopyright_noticerC   z | freshness_dategsa	file_sizez (%s))r   textfindr   r-   joinappend)
respr   
json_start	json_dataitemresult_itemrJ   rK   rL   rN   s
             r1   responserX   R   s   G,Jdii
,-I'"&&z26 $>.1(^L1N+I68n\2!"23G<=SFVAWX`Aa@bc,-e4!+.u5%	
 h##FB/33I>$(IIf$5K!>--fb9==>PQ!U-=%==!h++,<=!U^%;;!HHUB'++K8	!Wy%88!{#9$< Nr3   N)__doc__urllib.parser   jsonr   searx.engines.googler   r   r   r   about
categoriespagingmax_pagetime_range_supportr#   r+   r2   rX    r3   r1   <module>rc      sx    #  -  +"O	 
	
  
(x8>'r3   