
    w]                     ~    g d Z ddlZddlmZ ddlmZ ddlmZ dadadd	Z	ddZ
d Zd ZddZddZddZddZdS ))set_caa_hostnameget_image_listget_release_group_image_listget_release_group_image_frontget_image_frontget_image_back	get_image    N)compat)musicbrainz)_unicodezcoverartarchive.orgTFc                     | a |adS )al  Set the base hostname for Cover Art Archive requests.
    Defaults to 'coverartarchive.org', accessing over https.
    For backwards compatibility, `use_https` is False by default.

    :param str new_hostname: The hostname (and port) of the CAA server to connect to
    :param bool use_https: `True` if the host should be accessed using https. Default is `False`
N)hostnamehttps)new_hostname	use_httpss     4/usr/lib/python3/dist-packages/musicbrainzngs/caa.pyr   r      s     HEEE    releasec                    || g}|r|r|                     |d|           n|r|                     |           t          j        t          rdndt          dd                    |          z  dddf          }t          j                            d|           t          j	        d	          }|g}t          j
        | }t          j        d
|d          }	t          j        dk    rL|	                    dt          j                   t          j                            dt          j        z             t          j        ||	d          }
|r|
S t          |
          }t!          j        |          S )aF   Make a CAA request.

    :param imageid: ``front``, ``back`` or a number from the listing obtained
                    with :meth:`get_image_list`.
    :type imageid: str

    :param size: "250", "500", "1200"
    :type size: str or None

    :param entitytype: ``release`` or ``release-group``
    :type entitytype: str
    -r   httpz/%s/ zGET request for r	   )
debuglevelGETNz
User-Agentzrequesting with UA %s)appendr
   
urlunparser   r   joinr   _logdebugHTTPHandlerbuild_opener_MusicbrainzHttpRequest
_useragent
add_header
_safe_readr   jsonloads)mbidimageidsize
entitytypepathurlhttpHandlerhandlersopenerreqrespdatas               r   _caa_requestr5   $   s}    D 4 www-....	 G

$f


  C 339::: $222K}H (+F 
-eS$
?
?C##|[%;<<<69OOPPP!&#t44D    ~~z$r   c                      t          |           S )a  Get the list of cover art associated with a release.

    The return value is the deserialized response of the `JSON listing
    <http://musicbrainz.org/doc/Cover_Art_Archive/API#.2Frelease.2F.7Bmbid.7D.2F>`_
    returned by the Cover Art Archive API.

    If an error occurs then a :class:`~musicbrainzngs.ResponseError` will
    be raised with one of the following HTTP codes:

    * 400: `Releaseid` is not a valid UUID
    * 404: No release exists with an MBID of `releaseid`
    * 503: Ratelimit exceeded
    r5   )	releaseids    r   r   r   ^   s     	"""r   c                 $    t          | d          S )a  Get the list of cover art associated with a release group.

    The return value is the deserialized response of the `JSON listing
    <http://musicbrainz.org/doc/Cover_Art_Archive/API#.2Frelease-group.2F.7Bmbid.7D.2F>`_
    returned by the Cover Art Archive API.

    If an error occurs then a :class:`~musicbrainzngs.ResponseError` will
    be raised with one of the following HTTP codes:

    * 400: `Releaseid` is not a valid UUID
    * 404: No release exists with an MBID of `releaseid`
    * 503: Ratelimit exceeded
    release-group)r,   r7   )releasegroupids    r   r   r   o   s     ?CCCCr   c                 (    t          | d|d          S )zDownload the front cover art for a release group.
    The `size` argument and the possible error conditions are the same as for
    :meth:`get_image`.
    frontr:   r+   r,   r   )r;   r+   s     r   r   r      s$    
 ^W4 /1 1 1 1r   c                 &    t          | d|          S )zDownload the front cover art for a release.
    The `size` argument and the possible error conditions are the same as for
    :meth:`get_image`.
    r=   r+   r?   r8   r+   s     r   r   r      s    
 Yd3333r   c                 &    t          | d|          S )zDownload the back cover art for a release.
    The `size` argument and the possible error conditions are the same as for
    :meth:`get_image`.
    backrA   r?   rB   s     r   r   r      s    
 YT2222r   c                     t          |t                    rd|fz  }t          |t                    rd|fz  }t          | |||          S )a  Download cover art for a release. The coverart file to download
    is specified by the `coverid` argument.

    If `size` is not specified, download the largest copy present, which can be
    very large.

    If an error occurs then a :class:`~musicbrainzngs.ResponseError`
    will be raised with one of the following HTTP codes:

    * 400: `Releaseid` is not a valid UUID or `coverid` is invalid
    * 404: No release exists with an MBID of `releaseid`
    * 503: Ratelimit exceeded

    :param coverid: ``front``, ``back`` or a number from the listing obtained with
                    :meth:`get_image_list`
    :type coverid: int or str

    :param size: "250", "500", "1200" or None. If it is None, the largest
                 available picture will be downloaded. If the image originally
                 uploaded to the Cover Art Archive was smaller than the
                 requested size, only the original image will be returned.
    :type size: str or None

    :param entitytype: The type of entity for which to download the cover art.
                       This is either ``release`` or ``release-group``.
    :type entitytype: str
    :return: The binary image data
    :type: str
    z%dr>   )
isinstanceintr5   )r)   coveridr+   r,   s       r   r   r      sV    < '3 %'$$ thgDZHHHHr   )F)NNr   )N)Nr   )__all__r'   musicbrainzngsr
   r   musicbrainzngs.utilr   r   r   r   r5   r   r   r   r   r   r    r   r   <module>rM      s      ! ! ! ! ! ! & & & & & & ( ( ( ( ( (    7  7  7  7 t# # #"D D D"1 1 1 14 4 4 43 3 3 3"I "I "I "I "I "Ir   