
    i%                         U d Z ddlmZmZ ddlmZ ddlZddddddd	Zg Zd
ZdZ	dZ
dZeed<   	 g dZg Zeed<   	 d Zd Zd Zd Zd Zd Zy)a{  `Adobe Stock`_ is a service that gives access to millions of royalty-free
assets. Assets types include photos, vectors, illustrations, templates, 3D
assets, videos, motion graphics templates and audio tracks.

.. Adobe Stock: https://stock.adobe.com/

Configuration
=============

The engine has the following mandatory setting:

- SearXNG's :ref:`engine categories`
- Adobe-Stock's :py:obj:`adobe_order`
- Adobe-Stock's :py:obj:`adobe_content_types`

.. code:: yaml

  - name: adobe stock
    engine: adobe_stock
    shortcut: asi
    categories: [images]
    adobe_order: relevance
    adobe_content_types: ["photo", "illustration", "zip_vector", "template", "3d", "image"]

  - name: adobe stock video
    engine: adobe_stock
    network: adobe stock
    shortcut: asi
    categories: [videos]
    adobe_order: relevance
    adobe_content_types: ["video"]

Implementation
==============

    )datetime	timedelta)	urlencodeNzhttps://stock.adobe.com/Q5977430FJSON)websitewikidata_idofficial_api_documentationuse_official_apirequire_api_keyresultsT
   zhttps://stock.adobe.com adobe_order)photoillustration
zip_vectorvideotemplate3daudioimageadobe_content_typesc                 >   t         st        d      t        st        d      t        dvrt        dt               t        st        d      t	        t        t
              r"t        D ]  }|t        vst        d|z         y t        dt        t              z        )Nz'adobe_stock engine: categories is unsetz(adobe_stock engine: adobe_order is unset)	relevancefeaturedcreationnb_downloadszunsupported adobe_order: z0adobe_stock engine: adobe_content_types is unsetz8adobe_stock engine: adobe_content_types: '%s' is invalidzHadobe_stock engine: adobe_content_types must be a list of strings not %s)
categories
ValueErrorr   r   
isinstancelistADOBE_VALID_TYPEStype)_ts     */root/searxng/searx/engines/adobe_stock.pyinitr(   X   s    BCC CDDOO4[MBCC KLL%t,$ 	aA)) ![^_!_``	a VY]^qYrr
 	
    c                     | t         t        |d   dd}t        D ]  }|t        v rdnd|d| d<    t         dt        |       |d	<   |d
   dk(  rd|d   d<   |S )Npageno
pagination)klimitordersearch_pagesearch_type   r   zfilters[content_type:]z/de/Ajax/Search?urlsearxng_localeallzen-US,en;q=0.5headerszAccept-Language)results_per_pager   r#   r   base_urlr   )queryparamsargscontent_types       r'   requestr>   p   s     !h'#D * h=IM`=`fg$\N!45h  j 040ABF5M 5(/?y+,Mr)   c           
      Z    d| d   | d   | d   | d   | d   | d    d| d	    | d
   | d   d	S )Nzimages.htmlcontent_urltitle
asset_typecontent_thumb_extra_large_urlthumbnail_urlcontent_original_widthxcontent_original_heightformatauthor)	r   r4   rA   contentimg_srcthumbnail_src
resolution
img_formatrI    )items    r'   parse_image_itemrQ      sa    !M"g%78o.678$?X:Y9Z[8nx.
 
r)   c           
         | d   }d}d|j                         d d v r|}|j                  dd      d   }nod|v r|}|j                  dd      d   }nSt        |      dkD  rE|}d}|j                  d	      D ]-  }|d	| z  }t        |      dkD  s|j                         d
z   } n d| d   ||t        j                  | d         t        j                  | d         | d   | d   | d   d	S )NrA   r   .r2   r   ,2    u   …zvideos.htmlr@   time_durationcreation_daterD   video_small_preview_urlrB   )	r   r4   rA   rJ   lengthpublishedDate	thumbnail
iframe_srcmetadata)stripsplitlenisodateparse_durationr   fromisoformat)rP   rA   rJ   ws       r'   parse_video_itemrg      s   
 MEG
ekkmCR  C#A&	C#A&	Ubs# 	AqWE5zB0		 "M"((o)>?!//_0EF/*45& r)   c                 2   | d   }|j                  d      xs d}|j                  d      r|d   dz   |z   }| d   | d   ||d   d	   |d
   rt        j                  |d
         nd |d   rt        t	        |d   dz              nd | j                  d      dS )N
audio_datadescriptionr   albumz - r@   rA   previewr4   release_datedurationi  )secondsartist_name)r4   rA   rJ   r^   r\   r[   rI   )getr   re   r   round)rP   ri   rJ   s      r'   parse_audio_itemrs      s    l#Jnn]+1rG~~gW%-7 M"g +E2OYZhOi//
>0JKosMWXbMc)E*Z*@4*G$HIim((=)	 	r)   c                    g }| j                         }t        |d   t              ry |d   j                         D ]  }|d   j	                         dv rt        |      }n_|d   j	                         dk(  rt        |      }n=|d   j	                         dk(  rt        |      }nt        j                  d|d   |       |j                  |        |S )NitemsrB   )r   zpremium-imager   vectorr   r   zno handle for %s --> %s)jsonr!   r"   valueslowerrQ   rg   rs   loggererrorappend)respr   	json_resprP   results        r'   responser      s    G		I)G$d+'"))+ 
##%)]]%d+F,%%'72%d+F,%%'72%d+FLL2D4FMv
 Nr)   )__doc__r   r   urllib.parser   rc   aboutr   pagingr8   r9   r   str__annotations__r#   r   r"   r(   r>   rQ   rg   rs   r   rO   r)   r'   <module>r      s   #J ) "  *"&	 
	 $S  i  T $
0,!H$r)   