
    i                     P    d Z ddlZdddddddZdgZdZd	Zd
ZddddddZd Zd Z	y)a  IMDB - Internet Movie Database

Retrieves results from a basic search.  Advanced search options are not
supported.  IMDB's API is undocumented, here are some posts about:

- https://stackoverflow.com/questions/1966503/does-imdb-provide-an-api
- https://rapidapi.com/blog/how-to-use-imdb-api/

An alternative that needs IMDPro_ is `IMDb and Box Office Mojo
<https://developer.imdb.com/documentation>`_

.. __IMDPro: https://pro.imdb.com/login

    Nzhttps://imdb.com/Q37312FHTML)websitewikidata_idofficial_api_documentationuse_official_apirequire_api_keyresultsmoviesz=https://v2.sg.media-imdb.com/suggestion/{letter}/{query}.jsonz&https://imdb.com/{category}/{entry_id}nametitlekeywordcompanyepisode)nmttkwcoepc                     | j                  dd      j                         } t        j                  | d   |       |d<   |S )N _r   )letterqueryurl)replacelowersuggestion_urlformat)r   paramss     #/root/searxng/searx/engines/imdb.pyrequestr"   '   s=    MM#s#))+E"))q)GF5MM    c                    t        j                  | j                        }g }|j                  dg       D ]  }|d   }t        j                  |d d       }|t
        j                  d|d d |       >|d   }d|v r|d|d   z  z  }d}d	|v r|d
|d	   z  z  }d|v r|t        |d         dz   z  }d|v r||d   z  }|j                  di       j                  d      }|r8|j                  dd      \  }	}
d}|	j                  d      sd|z   }|	|z   dz   |
z   }|j                  |t        j                  ||      ||d        |S )Ndid   z"skip unknown category tag %s in %slqz (%s) rankz(%s) yz - siimageUrl.   zQL75_UX280_CR0,0,280,414__V1_)categoryentry_id)r   r   content	thumbnail)jsonloadstextgetsearch_categoriesloggererrorstrrsplitendswithappend	href_baser   )respsuggestionsr
   entryr4   categr   r5   	image_urlimage_url_nameimage_url_prefixmagics               r!   responserK   /   s   **TYY'KGb) +
 ;!%%hrl3=LL=x|XVc
%<WuSz))EU?wv..G%<s5:..G%<uSz!G IIc2&**:6	/8/?/?Q/G,N, 0E!**62&.47GGI '''J"&		
I+
Z Nr#   )
__doc__r7   about
categoriespagingr   rB   r;   r"   rK    r#   r!   <module>rQ      sa     #"&	 Z
	 Q4	!	Zcd 2r#   