
    i                     X    d Z ddlmZ ddlmZ ddddddd	Zd
ZdgZdZdZ	g dZ
d Zd Zy)a  Moviepilot is a German movie database, similar to IMDB or TMDB.  It doesn't
have any official API, but it uses JSON requests internally to fetch search
results and suggestions, that's being used in this implementation.

Moviepilot additionally allows to discover movies by certain categories
or filters, hence we provide the following syntax:

- Any normal search query -> Fetch search results by the query

- A query containing one of the category identifiers ``fsk``, ``genre``,
  ``jahr``, ``jahrzent``, ``land``, ``online``, ``stimmung`` will be used to
  search trending items by the provided filters, which are appended to the
  filter category after a ``-``.

Search examples:

- Normal: ``!mp Tom Cruise``
- By filter: ``!mp person-Ryan-Gosling``
- By filter: ``!mp fsk-0 land-deutschland genre-actionfilm``
- By filter: ``!mp jahrzehnt-2020er online-netflix``

For a list of all public filters, observe the url path when browsing

- https://www.moviepilot.de/filme/beste.

    )	urlencode)html_to_textzhttps://www.moviepilot.deNFJSONde)websiteofficial_api_documentationuse_official_apirequire_api_keyresultslanguageTmovieszIhttps://assets.cdn.moviepilot.de/files/{image_id}/fill/155/223/{filename})fskgenrejahr	jahrzehntlandonlinestimmungpersonc                    | j                  d      }g }|D ]B  }|j                  dd      }t        |      dk  r$|d   }|t        v s2|j                  |       D t        |      dk7  |d<   |d   r8|d   dd	}t         d
t        |       |d<   |D ]  }|dxx   d| z  cc<    |S | |d   dd}t         dt        |       |d<   |S )N -      r   	discoverypagenobeste)pageorderz/api/discovery?urlz&filters[]=suggest)qr   typez/api/search?)splitlenfilter_typesappendbase_urlr   )	queryparamsquery_partsdiscovery_filters
query_partfilter_category_and_valuefilter_categoryargsdiscovery_filters	            )/root/searxng/searx/engines/moviepilot.pyrequestr3   1   s   ++c"K! 	1
$.$4$4S!$<!()A-3A6l*$$Z0	1 /0A5F;k8$
 $*OIdO3DEu 1 	>5M{+;*<==M	> M 8$

 $*L40ABuM    c           	         g }| j                         }g }| j                  d   r|d   }n|}|D ]  }d|d   i}| j                  d   rdD cg c]  }|j                  |       }}t        |d   z   |d<   t	        dj                  |D cg c]  }|s|	 c}            |d<   t	        |j                  d	d
            |d<   |j                  d      rQt        j                  |d   |d         |d<   n0|d   |d<   dj                  |d   |d   |d   g      |d<   |d   |d<   |j                  |        |S c c}w c c}w )Nr   r   title)abstractsummarypathr    z | content
meta_short metadataimageimage_filename)image_idfilename	thumbnailz, classinfomore)	jsonsearch_paramsgetr(   r   join	image_urlformatr'   )respr   rF   json_resultsresultitemxcontent_lists           r2   responserR   U   sX   G99;DL+&I )k*3JKaFJJqMKLK"VF^3DK*5::,6TQRSq6T+UVDO+FJJ|R,HIDzz'"$-$4$4fWoX^_oXp$4$q[! -DK"ii&.&QW.(YZDO &wDt!$ N L6Ts   D9	D>D>)__doc__urllib.parser   searx.utilsr   aboutpaging
categoriesr(   rJ   r&   r3   rR    r4   r2   <module>rZ      sU   6 # $ +"&	 
Z
&W	\!Hr4   