
    g                     |    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y))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.orgTc                     | a |ay)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     '/opt/Tautulli/lib/musicbrainzngs/caa.pyr   r      s     HE    c                    || g}|r|r|j                  |d|       n|r|j                  |       t        j                  t        rdndt        ddj                  |      z  dddf      }t        j                  j                  d|       t        j                  d	      }|g}t        j                  | }t        j                  d
|d      }	t        j                  dk7  rP|	j                  dt        j                         t        j                  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_requestr4   $   s=    D4w-.	G


f


 C 39: $$2K}H  (+F 
-
-eS$
?C#|[%;%;<69O9OOP!!&#t4D  ~zz$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
    r4   )	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+   r6   )releasegroupids    r   r   r   o   s     ?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`.
    frontr9   r*   r+   r   )r:   r*   s     r   r   r      s    
 ^W4 /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>   r7   r*   s     r   r   r      s    
 Yd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`.
    backr@   r>   rA   s     r   r   r      s    
 YT22r   c                 x    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intr4   )r(   coveridr*   r+   s       r   r   r      s@    < '3'$$thgDZHHr   )F)NNrelease)N)NrH   )__all__r&   musicbrainzngsr
   r   musicbrainzngs.utilr   r   r   r   r4   r   r   r   r   r   r    r   r   <module>rM      sO     ! & ( 7 t#"D"143"Ir   