U
    'ciTF                    @   sx   d Z ddgZddlZddlZddlZddlZddlmZ ddlZddl	m
Z
 ddlmZmZ eeZG dd dZdS )	z: A simple and thin Python library for the Spotify Web API SpotifySpotifyException    N)defaultdict)r   )REQUESTS_SESSIONRetryc                <   @   s|  e Zd ZdZdZdZdddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?g<Zd@ZdAZdBZ	dCdDdCdCdCdCdEdCeedFdCfdGdHZ
dIdJ ZedKdL ZejdMdL ZdNdO ZdPdQ ZdRdS ZdTdU ZdFdVdWZdGdXdYZdHdZd[ZdId\d]Zd^d_ Zd`da ZdJdbdcZdKdddeZdfdg Zdhdi ZdLdldmZdMdndoZdpdq ZdNdrdsZ dOdudvZ!dPdwdxZ"dQdydzZ#dRd{d|Z$dSd}d~Z%dTddZ&dUddZ'dVddZ(dWddZ)dd Z*dXddZ+dYddZ,dZddZ-d[ddZ.dd Z/dd Z0d\ddZ1d]ddZ2d^ddZ3d_ddZ4d`ddZ5dd Z6daddZ7dbddZ8dd Z9dcddZ:ddddZ;deddZ<dd Z=dd Z>dfddZ?dd Z@dgddZAdd ZBdhddZCdiddĄZDdjddƄZEdkddȄZFddʄ ZGdd̄ ZHdd΄ ZIdlddЄZJdmdd҄ZKg fddԄZLg fddքZMg fdd؄ZNdnddڄZOdodd܄ZPdpddބZQdqddZRdrddZSdsddZTdtddZUduddZVdvddZWg fddZXg fddZYg fddZZdwddZ[dxddZ\dyddZ]dzddZ^d{ddZ_d|ddZ`g fddZag fd dZbg fddZcg fddZdd}ddZed~dd	Zfdd
dZgdddZhdddZidddZjdd Zkdd Zlg fddZmdd ZndddZodddZpdddZqdd d!Zrdd"d#Zsdd$d%Ztdd&d'Zudd(d)Zvdd*d+Zwdd,d-Zxdd.d/Zyd0d1 Zzdd2d3Z{d4d5 Z|d6d7 Z}d8d9 Z~d:d; Zd<d= Zd>d? Zdd@dAZddBdCZddDdEZdCS (  r   a  
        Example usage::

            import spotipy

            urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu'
            sp = spotipy.Spotify()

            artist = sp.artist(urn)
            print(artist)

            user = sp.user('plamere')
            print(user)
       )  i  i  i  i  ZADARZAUATZBEZBOZBRZBGCAZCLZCOCRZCYZCZZDKZDOZECZSVZEEZFIZFRZDEZGRGTZHNZHKZHUZISZIDZIEZITZJPLVZLILTZLUZMYZMTZMXZMCNLZNZZNINOZPAZPYPEZPHZPLZPTZSGESZSKZSEZCHZTWZTRZGBUSZUYz^spotify:(?:(?P<type>track|artist|album|playlist|show|episode|audiobook):(?P<id>[0-9A-Za-z]+)|user:(?P<username>[0-9A-Za-z]+):playlist:(?P<playlistid>[0-9A-Za-z]+))$z^(http[s]?:\/\/)?open.spotify.com\/(intl-\w\w\/)?(?P<type>track|artist|album|playlist|show|episode|user|audiobook)\/(?P<id>[0-9A-Za-z]+)(\?.*)?$z^[0-9A-Za-z]+$NT   g333333?c                 C   s|   d| _ || _|| _|| _|| _|| _|| _|p2| j| _|| _	|	| _
|
| _|| _t|tjrb|| _n|rp|   ntj| _dS )aO  
        Creates a Spotify API client.

        :param auth: An access token (optional)
        :param requests_session:
            A Requests session object or a truthy value to create one.
            A falsy value disables sessions.
            It should generally be a good idea to keep sessions enabled
            for performance reasons (connection pooling).
        :param client_credentials_manager:
            SpotifyClientCredentials object
        :param oauth_manager:
            SpotifyOAuth object
        :param auth_manager:
            SpotifyOauth, SpotifyClientCredentials,
            or SpotifyImplicitGrant object
        :param proxies:
            Definition of proxies (optional).
            See Requests doc https://2.python-requests.org/en/master/user/advanced/#proxies
        :param requests_timeout:
            Tell Requests to stop waiting for a response after a given
            number of seconds
        :param status_forcelist:
            Tell requests what type of status codes retries should occur on
        :param retries:
            Total number of retries to allow
        :param status_retries:
            Number of times to retry on bad status codes
        :param backoff_factor:
            A backoff factor to apply between attempts after the second try
            See urllib3 https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html
        :param language:
            The language parameter advertises what language the user prefers to see.
            See ISO-639-1 language code: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
        zhttps://api.spotify.com/v1/N)prefix_authclient_credentials_manageroauth_managerauth_managerproxiesrequests_timeoutdefault_retry_codesstatus_forcelistbackoff_factorretriesstatus_retrieslanguage
isinstancerequestsSession_session_build_sessionapi)selfauthZrequests_sessionr   r   r   r   r   r   r    r!   r   r"    r+   2/tmp/pip-unpacked-wheel-5vxoxy0m/spotipy/client.py__init__}   s"    2
zSpotify.__init__c                 C   s
   || _ d S N)r   )r)   r*   r+   r+   r,   set_auth   s    zSpotify.set_authc                 C   s   | j S r.   )_auth_managerr)   r+   r+   r,   r      s    zSpotify.auth_managerc                 C   s"   |d k	r|| _ n| jp| j| _ d S r.   )r0   r   r   )r)   r   r+   r+   r,   r      s    
c                 C   s&   t | ddr"t| jtr"| j  dS )z+Make sure the connection (pool) gets closedr&   N)getattrr#   r&   r   closer1   r+   r+   r,   __del__   s    zSpotify.__del__c              	   C   sb   t  | _t| jd dtddddg| j| j| jd}t j	j
|d}| jd| | jd	| d S )
NFGETPOSTPUTDELETE)totalconnectreadZallowed_methodsstatusr   r   )max_retrieszhttp://zhttps://)r$   r%   r&   r   r    	frozensetr!   r   r   adaptersHTTPAdaptermount)r)   retryadapterr+   r+   r,   r'      s    
	zSpotify._build_sessionc                 C   s`   | j rdd| j  iS | js i S z| jjdd}W n tk
rP   | j }Y nX dd| iS )NAuthorizationzBearer F)Zas_dict)r   r   Zget_access_token	TypeError)r)   tokenr+   r+   r,   _auth_headers   s    zSpotify._auth_headersc                 C   st  t |d}|ds| j| }|  }d|d krZ|d d |d< |d d= |rt||d< nd|d< |rtt||d< | jd k	r| j|d< td	| d
| d|	d d| d|	d
 z8| j
j||f|| j| jd|}|  | }W nj tjjk
r }	 z|	j}z,| }
|
	di }|	d}|	d}W n& tk
rd   |jpZd }d }Y nX td| d
| d|	d d|j d| 
 t|jd|j d| ||jdW 5 d }	~	X Y n tjjk
rF } z\|j}td z|jd j}W n ttfk
r   d }Y nX tdd|j d|dW 5 d }~X Y n tk
r^   d }Y nX td|  |S )N)paramshttpcontent_typerH   zContent-Typedatazapplication/jsonzAccept-LanguagezSending z to z with Params: z
 Headers: z and Body: )headersr   timeouterrormessagereasonzHTTP Error for z
 returned z due to z:
 )rP   rL   zMax Retries reachedr   r   z:
 Max Retries)rP   z	RESULTS: ) dict
startswithr   rG   jsondumpsr"   loggerdebuggetr&   requestr   r   raise_for_statusr$   
exceptions	HTTPErrorresponse
ValueErrortextrN   status_coder   urlrL   
RetryErrorargsrP   
IndexErrorAttributeErrorpath_url)r)   methodra   payloadrH   rc   rL   r]   results
http_errorZjson_responserN   msgrP   Zretry_errorrY   r+   r+   r,   _internal_call   s~    






4  

0



zSpotify._internal_callc                 K   s   |r| | | d|||S )Nr5   updaterl   r)   ra   rc   rh   kwargsr+   r+   r,   _get=  s    
zSpotify._getc                 K   s   |r| | | d|||S )Nr6   rm   ro   r+   r+   r,   _postC  s    
zSpotify._postc                 K   s   |r| | | d|||S )Nr8   rm   ro   r+   r+   r,   _deleteH  s    
zSpotify._deletec                 K   s   |r| | | d|||S )Nr7   rm   ro   r+   r+   r,   _putM  s    
zSpotify._putc                 C   s   |d r|  |d S dS dS )z returns the next result given a paged result

            Parameters:
                - result - a previously returned paged result
        nextNrq   r)   resultr+   r+   r,   ru   R  s    zSpotify.nextc                 C   s   |d r|  |d S dS dS )z returns the previous result given a paged result

            Parameters:
                - result - a previously returned paged result
        previousNrv   rw   r+   r+   r,   ry   ]  s    zSpotify.previousc                 C   s   |  d|}| jd| |dS )z returns a single track given the track's ID, URI or URL

            Parameters:
                - track_id - a spotify URI, URL or ID
                - market - an ISO 3166-1 alpha-2 country code.
        trackztracks/market_get_idrq   )r)   track_idr|   tridr+   r+   r,   rz   h  s    zSpotify.trackc                    s*    fdd|D } j dd| |dS )z returns a list of tracks given a list of track IDs, URIs, or URLs

            Parameters:
                - tracks - a list of spotify URIs, URLs or IDs. Maximum: 50 IDs.
                - market - an ISO 3166-1 alpha-2 country code.
        c                    s   g | ]}  d |qS rz   r~   .0tr1   r+   r,   
<listcomp>{  s     z"Spotify.tracks.<locals>.<listcomp>ztracks/?ids=,r{   rq   join)r)   tracksr|   tlistr+   r1   r,   r   s  s    zSpotify.tracksc                 C   s   |  d|}| d| S )z returns a single artist given the artist's ID, URI or URL

            Parameters:
                - artist_id - an artist ID, URI or URL
        artistartists/r}   r)   	artist_idr   r+   r+   r,   r   ~  s    zSpotify.artistc                    s&    fdd|D }  dd| S )z returns a list of artists given the artist IDs, URIs, or URLs

            Parameters:
                - artists - a list of  artist IDs, URIs or URLs
        c                    s   g | ]}  d |qS r   r   r   ar1   r+   r,   r     s     z#Spotify.artists.<locals>.<listcomp>zartists/?ids=r   r   )r)   artistsr   r+   r1   r,   r     s    zSpotify.artists   r   c                 C   s@   |rt dt |p|}| d|}| jd| d ||||dS )a%   Get Spotify catalog information about an artist's albums

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `artist_albums(..., include_groups='...')` instead.

            Parameters:
                - artist_id - the artist ID, URI or URL
                - include_groups - the types of items to return. One or more of 'album', 'single',
                                   'appears_on', 'compilation'. If multiple types are desired,
                                   pass in a comma separated string; e.g., 'album,single'.
                - country - limit the response to one particular country.
                - limit  - the number of albums to return
                - offset - the index of the first album to return
        zYou're using `artist_albums(..., album_type='...')` which will be removed in future versions. Please adjust your code accordingly by using `artist_albums(..., include_groups='...')` instead.r   r   z/albums)include_groupscountrylimitoffsetwarningswarnDeprecationWarningr~   rq   )r)   r   Z
album_typer   r   r   r   r   r+   r+   r,   artist_albums  s    
zSpotify.artist_albumsc                 C   s"   |  d|}| jd| d |dS )z Get Spotify catalog information about an artist's top 10 tracks
            by country.

            Parameters:
                - artist_id - the artist ID, URI or URL
                - country - limit the response to one particular country.
        r   r   z/top-tracks)r   r}   )r)   r   r   r   r+   r+   r,   artist_top_tracks  s    	zSpotify.artist_top_tracksc                 C   s*   t dt | d|}| d| d S )a~   Get Spotify catalog information about artists similar to an
            identified artist. Similarity is based on analysis of the
            Spotify community's listening history.

            .. deprecated::
            This endpoint has been removed by Spotify and is no longer available.

            Parameters:
                - artist_id - the artist ID, URI or URL
        zUYou're using `artist_related_artists(...)`, which is marked as deprecated by Spotify.r   r   z/related-artistsr   r   r+   r+   r,   artist_related_artists  s    zSpotify.artist_related_artistsc                 C   s<   |  d|}|dk	r*| d| d | S | d| S dS )z returns a single album given the album's ID, URIs or URL

            Parameters:
                - album_id - the album ID, URI or URL
                - market - an ISO 3166-1 alpha-2 country code
        albumNalbums/?market=r}   )r)   album_idr|   r   r+   r+   r,   r     s    zSpotify.album2   c                 C   s&   |  d|}| jd| d |||dS )aJ   Get Spotify catalog information about an album's tracks

            Parameters:
                - album_id - the album ID, URI or URL
                - limit  - the number of items to return
                - offset - the index of the first item to return
                - market - an ISO 3166-1 alpha-2 country code.

        r   r   z/tracks/r   r   r|   r}   )r)   r   r   r   r|   r   r+   r+   r,   album_tracks  s    
   zSpotify.album_tracksc                    sN    fdd|D }|dk	r6  dd| d | S   dd| S dS )z returns a list of albums given the album IDs, URIs, or URLs

            Parameters:
                - albums - a list of  album IDs, URIs or URLs
                - market - an ISO 3166-1 alpha-2 country code
        c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z"Spotify.albums.<locals>.<listcomp>Nzalbums/?ids=r   &market=r   )r)   albumsr|   r   r+   r1   r,   r     s    zSpotify.albumsc                 C   s   |  d|}| jd| |dS )a   returns a single show given the show's ID, URIs or URL

            Parameters:
                - show_id - the show ID, URI or URL
                - market - an ISO 3166-1 alpha-2 country code.
                           The show must be available in the given market.
                           If user-based authorization is in use, the user's country
                           takes precedence. If neither market nor user country are
                           provided, the content is considered unavailable for the client.
        showshows/r{   r}   )r)   show_idr|   r   r+   r+   r,   r     s    zSpotify.showc                    s*    fdd|D } j dd| |dS )a0   returns a list of shows given the show IDs, URIs, or URLs

            Parameters:
                - shows - a list of show IDs, URIs or URLs
                - market - an ISO 3166-1 alpha-2 country code.
                           Only shows available in the given market will be returned.
                           If user-based authorization is in use, the user's country
                           takes precedence. If neither market nor user country are
                           provided, the content is considered unavailable for the client.
        c                    s   g | ]}  d |qS r   r   r   sr1   r+   r,   r     s     z!Spotify.shows.<locals>.<listcomp>zshows/?ids=r   r{   r   )r)   showsr|   r   r+   r1   r,   r     s    zSpotify.showsc                 C   s&   |  d|}| jd| d |||dS )a   Get Spotify catalog information about a show's episodes

            Parameters:
                - show_id - the show ID, URI or URL
                - limit  - the number of items to return
                - offset - the index of the first item to return
                - market - an ISO 3166-1 alpha-2 country code.
                           Only episodes available in the given market will be returned.
                           If user-based authorization is in use, the user's country
                           takes precedence. If neither market nor user country are
                           provided, the content is considered unavailable for the client.
        r   r   z
/episodes/r   r}   )r)   r   r   r   r|   r   r+   r+   r,   show_episodes   s    
   zSpotify.show_episodesc                 C   s   |  d|}| jd| |dS )a*   returns a single episode given the episode's ID, URIs or URL

            Parameters:
                - episode_id - the episode ID, URI or URL
                - market - an ISO 3166-1 alpha-2 country code.
                           The episode must be available in the given market.
                           If user-based authorization is in use, the user's country
                           takes precedence. If neither market nor user country are
                           provided, the content is considered unavailable for the client.
        episodez	episodes/r{   r}   )r)   Z
episode_idr|   r   r+   r+   r,   r   3  s    zSpotify.episodec                    s*    fdd|D } j dd| |dS )a?   returns a list of episodes given the episode IDs, URIs, or URLs

            Parameters:
                - episodes - a list of episode IDs, URIs or URLs
                - market - an ISO 3166-1 alpha-2 country code.
                           Only episodes available in the given market will be returned.
                           If user-based authorization is in use, the user's country
                           takes precedence. If neither market nor user country are
                           provided, the content is considered unavailable for the client.
        c                    s   g | ]}  d |qS r   r   r   er1   r+   r,   r   N  s     z$Spotify.episodes.<locals>.<listcomp>zepisodes/?ids=r   r{   r   )r)   episodesr|   r   r+   r1   r,   r   B  s    zSpotify.episodes
   rz   c                 C   s   | j d|||||dS )a|   searches for an item

            Parameters:
                - q - the search query (see how to write a query in the
                      official documentation https://developer.spotify.com/documentation/web-api/reference/search/)  # noqa
                - limit - the number of items to return (min = 1, default = 10, max = 50). The limit is applied
                          within each type, not on the total response.
                - offset - the index of the first item to return
                - type - the types of items to return. One or more of 'artist', 'album',
                         'track', 'playlist', 'show', and 'episode'.  If multiple types are desired,
                         pass in a comma separated string; e.g., 'track,album,episode'.
                - market - An ISO 3166-1 alpha-2 country code or the string
                           from_token.
        searchqr   r   typer|   rv   )r)   r   r   r   r   r|   r+   r+   r,   r   Q  s         zSpotify.searchc                 C   sN   t dt |s| j}t|ts.t|ts.g }t dt | ||||||S )ah   (experimental) Searches multiple markets for an item

            Parameters:
                - q - the search query (see how to write a query in the
                      official documentation https://developer.spotify.com/documentation/web-api/reference/search/)  # noqa
                - limit  - the number of items to return (min = 1, default = 10, max = 50). If a search is to be done on multiple
                            markets, then this limit is applied to each market. (e.g. search US, CA, MX each with a limit of 10).
                            If multiple types are specified, this applies to each type.
                - offset - the index of the first item to return
                - type - the types of items to return. One or more of 'artist', 'album',
                         'track', 'playlist', 'show', or 'episode'. If multiple types are desired, pass in a comma separated string.
                - markets - A list of ISO 3166-1 alpha-2 country codes. Search all country markets by default.
                - total - the total number of results to return across multiple markets and types.
        zSearching multiple markets is an experimental feature. Please be aware that this method's inputs and outputs can change in the future.z0Searching multiple markets is poorly performing.)r   r   UserWarningcountry_codesr#   listtuple_search_multiple_markets)r)   r   r   r   r   marketsr9   r+   r+   r,   search_marketsd  s    zSpotify.search_marketsc                 C   s   |  d| S )z Gets basic profile information about a Spotify User

            Parameters:
                - user - the id of the usr
        users/rv   )r)   userr+   r+   r,   r     s    zSpotify.userc                 C   s   | j d||dS )z Get current user playlists without required getting his profile
            Parameters:
                - limit  - the number of items to return
                - offset - the index of the first item to return
        zme/playlistsr   r   rv   )r)   r   r   r+   r+   r,   current_user_playlists  s    zSpotify.current_user_playlistsr   c                 C   s*   |  d|}| jd| ||d|dS )a   Gets playlist by id.

            Parameters:
                - playlist - the id of the playlist
                - fields - which fields to return
                - market - An ISO 3166-1 alpha-2 country code or the
                           string from_token.
                - additional_types - list of item types to return.
                                     valid types are: track and episode
        playlist
playlists/r   )fieldsr|   additional_typesr~   rq   r   )r)   playlist_idr   r|   r   plidr+   r+   r,   r     s    zSpotify.playlistd   c                 C   s    t dt | ||||||S )a   Get full details of the tracks of a playlist.

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist_items(playlist_id, ..., additional_types=('track',))` instead.

            Parameters:
                - playlist_id - the playlist ID, URI or URL
                - fields - which fields to return
                - limit - the maximum number of tracks to return
                - offset - the index of the first track to return
                - market - an ISO 3166-1 alpha-2 country code.
                - additional_types - list of item types to return.
                                     valid types are: track and episode
        zUYou should use `playlist_items(playlist_id, ...,additional_types=('track',))` instead)r   r   r   playlist_items)r)   r   r   r   r   r|   r   r+   r+   r,   playlist_tracks  s     zSpotify.playlist_tracksrz   r   c              	   C   s0   |  d|}| jd| d||||d|dS )a   Get full details of the tracks and episodes of a playlist.

            Parameters:
                - playlist_id - the playlist ID, URI or URL
                - fields - which fields to return
                - limit - the maximum number of tracks to return
                - offset - the index of the first track to return
                - market - an ISO 3166-1 alpha-2 country code.
                - additional_types - list of item types to return.
                                     valid types are: track and episode
        r   r   /tracksr   )r   r   r   r|   r   r   )r)   r   r   r   r   r|   r   r   r+   r+   r,   r     s    
zSpotify.playlist_itemsc                 C   s   |  d|}| d| dS )z} Get cover image of a playlist.

            Parameters:
                - playlist_id - the playlist ID, URI or URL
        r   r   /imagesr}   )r)   r   r   r+   r+   r,   playlist_cover_image  s    zSpotify.playlist_cover_imagec                 C   s$   |  d|}| jd| d|ddS )a   Replace the image used to represent a specific playlist

            Parameters:
                - playlist_id - the id of the playlist
                - image_b64 - image data as a Base64 encoded JPEG image string
                    (maximum payload size is 256 KB)
        r   r   r   z
image/jpeg)rh   rJ   r~   rt   )r)   r   Z	image_b64r   r+   r+   r,   playlist_upload_cover_image  s    
z#Spotify.playlist_upload_cover_imagec                 C   s6   t dt |dkr&| d| dS | j|||dS )at   Gets a single playlist of a user

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist(playlist_id)` instead.

            Parameters:
                - user - the id of the user
                - playlist_id - the id of the playlist
                - fields - which fields to return
        z.You should use `playlist(playlist_id)` insteadNr   z/starred)r   r|   )r   r   r   rq   r   )r)   r   r   r   r|   r+   r+   r,   user_playlist  s    zSpotify.user_playlistc                 C   s    t dt | j|||||dS )aZ   Get full details of the tracks of a playlist owned by a user.

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist_tracks(playlist_id)` instead.

            Parameters:
                - user - the id of the user
                - playlist_id - the id of the playlist
                - fields - which fields to return
                - limit - the maximum number of tracks to return
                - offset - the index of the first track to return
                - market - an ISO 3166-1 alpha-2 country code.
        z5You should use `playlist_tracks(playlist_id)` instead)r   r   r   r|   )r   r   r   r   )r)   r   r   r   r   r   r|   r+   r+   r,   user_playlist_tracks  s    zSpotify.user_playlist_tracksc                 C   s   | j d| d||dS )z Gets playlists of a user

            Parameters:
                - user - the id of the usr
                - limit  - the number of items to return
                - offset - the index of the first item to return
        r   
/playlistsr   rv   )r)   r   r   r   r+   r+   r,   user_playlists5  s
    
  zSpotify.user_playlistsF c                 C   s$   ||||d}| j d| d|dS )a`   Creates a playlist for a user

            Parameters:
                - user - the id of the user
                - name - the name of the playlist
                - public - is the created playlist public
                - collaborative - is the created playlist collaborative
                - description - the description of the playlist
        )namepubliccollaborativedescriptionr   r   rh   )rr   )r)   r   r   r   r   r   rK   r+   r+   r,   user_playlist_createA  s    zSpotify.user_playlist_createc                 C   s   t dt | |||||S )a   This function is no longer in use, please use the recommended function in the warning!

            Changes a playlist's name and/or public/private state

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist_change_details(playlist_id, ...)` instead.

            Parameters:
                - user - the id of the user
                - playlist_id - the id of the playlist
                - name - optional name of the playlist
                - public - optional is the playlist public
                - collaborative - optional is the playlist collaborative
                - description - optional description of the playlist
        zBYou should use `playlist_change_details(playlist_id, ...)` instead)r   r   r   playlist_change_details)r)   r   r   r   r   r   r   r+   r+   r,   user_playlist_change_detailsT  s    
 z$Spotify.user_playlist_change_detailsc                 C   s   t dt | |S )a   This function is no longer in use, please use the recommended function in the warning!

            Unfollows (deletes) a playlist for a user

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `current_user_unfollow_playlist(playlist_id)` instead.

            Parameters:
                - user - the id of the user
                - name - the name of the playlist
        zDYou should use `current_user_unfollow_playlist(playlist_id)` instead)r   r   r   current_user_unfollow_playlist)r)   r   r   r+   r+   r,   user_playlist_unfollowu  s
    zSpotify.user_playlist_unfollowc                    s,   t dt  fdd|D } |||S )a*   This function is no longer in use, please use the recommended function in the warning!

            Adds tracks to a playlist

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist_add_items(playlist_id, tracks)` instead.

            Parameters:
                - user - the id of the user
                - playlist_id - the id of the playlist
                - tracks - a list of track URIs, URLs or IDs
                - position - the position to add the tracks
        z@You should use `playlist_add_items(playlist_id, tracks)` insteadc                    s   g | ]}  d |qS r   _get_urir   tidr1   r+   r,   r     s     z4Spotify.user_playlist_add_tracks.<locals>.<listcomp>r   r   r   playlist_add_items)r)   r   r   r   positionr+   r1   r,   user_playlist_add_tracks  s    z Spotify.user_playlist_add_tracksc                    s,   t dt  fdd|D } |||S )a2   This function is no longer in use, please use the recommended function in the warning!

            Adds episodes to a playlist

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist_add_items(playlist_id, episodes)` instead.

            Parameters:
                - user - the id of the user
                - playlist_id - the id of the playlist
                - episodes - a list of track URIs, URLs or IDs
                - position - the position to add the episodes
        zBYou should use `playlist_add_items(playlist_id, episodes)` insteadc                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z6Spotify.user_playlist_add_episodes.<locals>.<listcomp>r   )r)   r   r   r   r   r+   r1   r,   user_playlist_add_episodes  s    z"Spotify.user_playlist_add_episodesc                 C   s   t dt | ||S )a   This function is no longer in use, please use the recommended function in the warning!

            Replace all tracks in a playlist for a user

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist_replace_items(playlist_id, tracks)` instead.

            Parameters:
                - user - the id of the user
                - playlist_id - the id of the playlist
                - tracks - the list of track ids to add to the playlist
        zDYou should use `playlist_replace_items(playlist_id, tracks)` instead)r   r   r   playlist_replace_items)r)   r   r   r   r+   r+   r,   user_playlist_replace_tracks  s
    z$Spotify.user_playlist_replace_tracks   c                 C   s   t dt | |||||S )aC   This function is no longer in use, please use the recommended function in the warning!

            Reorder tracks in a playlist from a user

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist_reorder_items(playlist_id, ...)` instead.

            Parameters:
                - user - the id of the user
                - playlist_id - the id of the playlist
                - range_start - the position of the first track to be reordered
                - range_length - optional the number of tracks to be reordered
                                 (default: 1)
                - insert_before - the position where the tracks should be
                                  inserted
                - snapshot_id - optional playlist's snapshot ID
        zAYou should use `playlist_reorder_items(playlist_id, ...)` instead)r   r   r   playlist_reorder_items)r)   r   r   range_startinsert_beforerange_lengthsnapshot_idr+   r+   r,   user_playlist_reorder_tracks  s     z$Spotify.user_playlist_reorder_tracksc                 C   s   t dt | |||S )a   This function is no longer in use, please use the recommended function in the warning!

            Removes all occurrences of the given tracks from the given playlist

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist_remove_all_occurrences_of_items(playlist_id, tracks)` instead.

            Parameters:
                - user - the id of the user
                - playlist_id - the id of the playlist
                - tracks - the list of track ids to remove from the playlist
                - snapshot_id - optional id of the playlist snapshot
        zVYou should use `playlist_remove_all_occurrences_of_items(playlist_id, tracks)` instead)r   r   r   (playlist_remove_all_occurrences_of_items)r)   r   r   r   r   r+   r+   r,   .user_playlist_remove_all_occurrences_of_tracks  s    z6Spotify.user_playlist_remove_all_occurrences_of_tracksc           	      C   sv   t dt | d|}g }|D ]$}|| d|d |d d q d|i}|rZ||d< | jd	| d
| d|dS )aG   This function is no longer in use, please use the recommended function in the warning!

            Removes specific occurrences of the given tracks from the given playlist

            .. deprecated::
            This endpoint has been removed by Spotify and is no longer available.

            Parameters:
                - user - the id of the user
                - playlist_id - the id of the playlist
                - tracks - an array of objects containing Spotify URIs of the
                    tracks to remove with their current positions in the
                    playlist.  For example:
                        [  { "uri":"4iV5W9uYEdYUVa79Axb7Rh", "positions":[2] },
                        { "uri":"1301WleyT98MSxVHPZCA6M", "positions":[7] } ]
                - snapshot_id - optional id of the playlist snapshot
        zrYou're using `user_playlist_remove_specific_occurrences_of_tracks(...)`, which is marked as deprecated by Spotify.r   rz   uri	positionsr   r   r   r   r   z/playlists/r   r   )r   r   r   r~   appendr   rs   )	r)   r   r   r   r   r   ftrackstrrh   r+   r+   r,   3user_playlist_remove_specific_occurrences_of_tracks  s&     z;Spotify.user_playlist_remove_specific_occurrences_of_tracksc                 C   s   t dt | |S )a   This function is no longer in use, please use the recommended function in the warning!

            Add the current authenticated user as a follower of a playlist.

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `current_user_follow_playlist(playlist_id)` instead.

            Parameters:
                - playlist_owner_id - the user id of the playlist owner
                - playlist_id - the id of the playlist
        zBYou should use `current_user_follow_playlist(playlist_id)` instead)r   r   r   current_user_follow_playlist)r)   playlist_owner_idr   r+   r+   r,   user_playlist_follow_playlist4  s
    z%Spotify.user_playlist_follow_playlistc                 C   s   t dt | ||S )a   This function is no longer in use, please use the recommended function in the warning!

            Check to see if the given users are following the given playlist

            .. deprecated::
            This method is deprecated and may be removed in a future version. Use
            `playlist_is_following(playlist_id, user_ids)` instead.

            Parameters:
                - playlist_owner_id - the user id of the playlist owner
                - playlist_id - the id of the playlist
                - user_ids - the ids of the users that you want to check to see
                    if they follow the playlist. Maximum: 5 ids.
        zEYou should use `playlist_is_following(playlist_id, user_ids)` instead)r   r   r   playlist_is_following)r)   r  r   user_idsr+   r+   r,   user_playlist_is_followingG  s
    z"Spotify.user_playlist_is_followingc                 C   sh   i }t |tr||d< t |tr(||d< t |tr:||d< t |trL||d< | jd| d| |dS )a   Changes a playlist's name and/or public/private state,
            collaborative state, and/or description

            Parameters:
                - playlist_id - the id of the playlist
                - name - optional name of the playlist
                - public - optional is the playlist public
                - collaborative - optional is the playlist collaborative
                - description - optional description of the playlist
        r   r   r   r   r   r   r   )r#   strboolrt   r~   )r)   r   r   r   r   r   rK   r+   r+   r,   r   ^  s    



 zSpotify.playlist_change_detailsc                 C   s   |  d| d| dS )z Unfollows (deletes) a playlist for the current authenticated
            user

            Parameters:
                - playlist_id - the id of the playlist
        r   r   
/followers)rs   r~   )r)   r   r+   r+   r,   r   ~  s    z&Spotify.current_user_unfollow_playlistc                    s6     d|} fdd|D } jd| d||dS )z Adds tracks/episodes to a playlist

            Parameters:
                - playlist_id - the id of the playlist
                - items - a list of track/episode URIs or URLs
                - position - the position to add the tracks
        r   c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z.Spotify.playlist_add_items.<locals>.<listcomp>r   r   )rh   r   )r~   rr   )r)   r   itemsr   r   r   r+   r1   r,   r     s    

zSpotify.playlist_add_itemsc                    s<     d|} fdd|D }d|i} jd| d|dS )z Replace all tracks/episodes in a playlist

            Parameters:
                - playlist_id - the id of the playlist
                - items - list of track/episode ids to comprise playlist
        r   c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z2Spotify.playlist_replace_items.<locals>.<listcomp>urisr   r   r   r   )r)   r   r
  r   r   rh   r+   r1   r,   r     s    
 zSpotify.playlist_replace_itemsc                 C   s:   |  d|}|||d}|r$||d< | jd| d|dS )a   Reorder tracks in a playlist

            Parameters:
                - playlist_id - the id of the playlist
                - range_start - the position of the first track to be reordered
                - range_length - optional the number of tracks to be reordered
                                 (default: 1)
                - insert_before - the position where the tracks should be
                                  inserted
                - snapshot_id - optional playlist's snapshot ID
        r   )r   r   r   r   r   r   r   r   )r)   r   r   r   r   r   r   rh   r+   r+   r,   r     s    
 zSpotify.playlist_reorder_itemsc                    sR     d|} fdd|D }ddd |D i}|r<||d<  jd| d|d	S )
a<   Removes all occurrences of the given tracks/episodes from the given playlist

            Parameters:
                - playlist_id - the id of the playlist
                - items - list of track/episode ids to remove from the playlist
                - snapshot_id - optional id of the playlist snapshot

        r   c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     zDSpotify.playlist_remove_all_occurrences_of_items.<locals>.<listcomp>r   c                 S   s   g | ]}d |iqS )r   r+   )r   rz   r+   r+   r,   r     s     r   r   r   r   )r~   rs   )r)   r   r
  r   r   r   rh   r+   r1   r,   r     s    
 z0Spotify.playlist_remove_all_occurrences_of_itemsc                 C   sd   |  d|}g }|D ]$}|| d|d |d d qd|i}|rN||d< | jd| d	|d
S )aK   Removes all occurrences of the given tracks from the given playlist

            Parameters:
                - playlist_id - the id of the playlist
                - items - an array of objects containing Spotify URIs of the
                    tracks/episodes to remove with their current positions in
                    the playlist.  For example:
                        [  { "uri":"4iV5W9uYEdYUVa79Axb7Rh", "positions":[2] },
                        { "uri":"1301WleyT98MSxVHPZCA6M", "positions":[7] } ]
                - snapshot_id - optional id of the playlist snapshot
        r   rz   r   r   r   r   r   r   r   r   )r~   r   r   rs   )r)   r   r
  r   r   r   r   rh   r+   r+   r,   -playlist_remove_specific_occurrences_of_items  s    
 z5Spotify.playlist_remove_specific_occurrences_of_itemsc                 C   s   | j d| dd|idS )z
        Add the current authenticated user as a follower of a playlist.

        Parameters:
            - playlist_id - the id of the playlist

        r   r	  r   r   rt   )r)   r   r   r+   r+   r,   r    s    
z$Spotify.current_user_follow_playlistc                 C   s    d| dd | }| |S )a$  
        Check to see if the given users are following the given playlist

        Parameters:
            - playlist_id - the id of the playlist
            - user_ids - the ids of the users that you want to check to see
                if they follow the playlist. Maximum: 5 ids.

        r   z/followers/contains?ids=r   r   rq   )r)   r   r  endpointr+   r+   r,   r  	  s    zSpotify.playlist_is_followingc                 C   s
   |  dS )zv Get detailed profile information about the current user.
            An alias for the 'current_user' method.
        zme/rv   r1   r+   r+   r,   me  s    z
Spotify.mec                 C   s   |   S )zl Get detailed profile information about the current user.
            An alias for the 'me' method.
        )r  r1   r+   r+   r,   current_user  s    zSpotify.current_userc                 C   s   | j d|d|dS )aa   Get information about the current users currently playing track.

            Parameters:
                - market - An ISO 3166-1 alpha-2 country code or the
                           string from_token.
                - additional_types - list of item types to return.
                                     valid types are: track and episode
        me/player/currently-playingr   r|   r   r   r)   r|   r   r+   r+   r,   current_user_playing_track$  s
    	z"Spotify.current_user_playing_trackc                 C   s   | j d|||dS )aN   Gets a list of the albums saved in the current authorized user's
            "Your Music" library

            Parameters:
                - limit - the number of albums to return (MAX_LIMIT=50)
                - offset - the index of the first album to return
                - market - an ISO 3166-1 alpha-2 country code.

        z	me/albumsr   rv   r)   r   r   r|   r+   r+   r,   current_user_saved_albums3  s    
z!Spotify.current_user_saved_albumsc                    s&    fdd|D }  dd| S )z Add one or more albums to the current user's
            "Your Music" library.
            Parameters:
                - albums - a list of album URIs, URLs or IDs
        c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r   F  s     z9Spotify.current_user_saved_albums_add.<locals>.<listcomp>zme/albums?ids=r   rt   r   r)   r   alistr+   r1   r,   current_user_saved_albums_add?  s    z%Spotify.current_user_saved_albums_addc                    s&    fdd|D }  dd| S )z Remove one or more albums from the current user's
            "Your Music" library.

            Parameters:
                - albums - a list of album URIs, URLs or IDs
        c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r   P  s     z<Spotify.current_user_saved_albums_delete.<locals>.<listcomp>zme/albums/?ids=r   rs   r   r  r+   r1   r,    current_user_saved_albums_deleteI  s    z(Spotify.current_user_saved_albums_deletec                    s&    fdd|D }  dd| S )u    Check if one or more albums is already saved in
            the current Spotify user’s “Your Music” library.

            Parameters:
                - albums - a list of album URIs, URLs or IDs
        c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r   Z  s     z>Spotify.current_user_saved_albums_contains.<locals>.<listcomp>zme/albums/contains?ids=r   r   r  r+   r1   r,   "current_user_saved_albums_containsS  s    z*Spotify.current_user_saved_albums_containsc                 C   s   | j d|||dS )a>   Gets a list of the tracks saved in the current authorized user's
            "Your Music" library

            Parameters:
                - limit - the number of tracks to return
                - offset - the index of the first track to return
                - market - an ISO 3166-1 alpha-2 country code

        z	me/tracksr   rv   r  r+   r+   r,   current_user_saved_tracks]  s    
z!Spotify.current_user_saved_tracksc                    s2   g }|dk	r fdd|D }  dd| S )z Add one or more tracks to the current user's
            "Your Music" library.

            Parameters:
                - tracks - a list of track URIs, URLs or IDs
        Nc                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r   r  s     z9Spotify.current_user_saved_tracks_add.<locals>.<listcomp>me/tracks/?ids=r   r  r)   r   r   r+   r1   r,   current_user_saved_tracks_addi  s    z%Spotify.current_user_saved_tracks_addc                    s2   g }|dk	r fdd|D }  dd| S )z Remove one or more tracks from the current user's
            "Your Music" library.

            Parameters:
                - tracks - a list of track URIs, URLs or IDs
        Nc                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r   ~  s     z<Spotify.current_user_saved_tracks_delete.<locals>.<listcomp>r   r   r  r!  r+   r1   r,    current_user_saved_tracks_deleteu  s    z(Spotify.current_user_saved_tracks_deletec                    s2   g }|dk	r fdd|D }  dd| S )u    Check if one or more tracks is already saved in
            the current Spotify user’s “Your Music” library.

            Parameters:
                - tracks - a list of track URIs, URLs or IDs
        Nc                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z>Spotify.current_user_saved_tracks_contains.<locals>.<listcomp>zme/tracks/contains?ids=r   r   r!  r+   r1   r,   "current_user_saved_tracks_contains  s    z*Spotify.current_user_saved_tracks_containsc                 C   s   | j d|||dS )aD   Gets a list of the episodes saved in the current authorized user's
            "Your Music" library

            Parameters:
                - limit - the number of episodes to return
                - offset - the index of the first episode to return
                - market - an ISO 3166-1 alpha-2 country code

        zme/episodesr   rv   r  r+   r+   r,   current_user_saved_episodes  s    
z#Spotify.current_user_saved_episodesc                    s2   g }|dk	r fdd|D }  dd| S )z Add one or more episodes to the current user's
            "Your Music" library.

            Parameters:
                - episodes - a list of episode URIs, URLs or IDs
        Nc                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z;Spotify.current_user_saved_episodes_add.<locals>.<listcomp>me/episodes/?ids=r   r  r)   r   Zelistr+   r1   r,   current_user_saved_episodes_add  s    z'Spotify.current_user_saved_episodes_addc                    s2   g }|dk	r fdd|D }  dd| S )z Remove one or more episodes from the current user's
            "Your Music" library.

            Parameters:
                - episodes - a list of episode URIs, URLs or IDs
        Nc                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z>Spotify.current_user_saved_episodes_delete.<locals>.<listcomp>r&  r   r  r'  r+   r1   r,   "current_user_saved_episodes_delete  s    z*Spotify.current_user_saved_episodes_deletec                    s2   g }|dk	r fdd|D }  dd| S )u    Check if one or more episodes is already saved in
            the current Spotify user’s “Your Music” library.

            Parameters:
                - episodes - a list of episode URIs, URLs or IDs
        Nc                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z@Spotify.current_user_saved_episodes_contains.<locals>.<listcomp>zme/episodes/contains?ids=r   r   r'  r+   r1   r,   $current_user_saved_episodes_contains  s    z,Spotify.current_user_saved_episodes_containsc                 C   s   | j d|||dS )a;   Gets a list of the shows saved in the current authorized user's
            "Your Music" library

            Parameters:
                - limit - the number of shows to return
                - offset - the index of the first show to return
                - market - an ISO 3166-1 alpha-2 country code

        zme/showsr   rv   r  r+   r+   r,   current_user_saved_shows  s    
z Spotify.current_user_saved_showsc                    s&    fdd|D }  dd| S )z Add one or more albums to the current user's
            "Your Music" library.
            Parameters:
                - shows - a list of show URIs, URLs or IDs
        c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z8Spotify.current_user_saved_shows_add.<locals>.<listcomp>zme/shows?ids=r   r  r)   r   slistr+   r1   r,   current_user_saved_shows_add  s    z$Spotify.current_user_saved_shows_addc                    s&    fdd|D }  dd| S )z Remove one or more shows from the current user's
            "Your Music" library.

            Parameters:
                - shows - a list of show URIs, URLs or IDs
        c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z;Spotify.current_user_saved_shows_delete.<locals>.<listcomp>zme/shows/?ids=r   r  r,  r+   r1   r,   current_user_saved_shows_delete  s    z'Spotify.current_user_saved_shows_deletec                    s&    fdd|D }  dd| S )u    Check if one or more shows is already saved in
            the current Spotify user’s “Your Music” library.

            Parameters:
                - shows - a list of show URIs, URLs or IDs
        c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z=Spotify.current_user_saved_shows_contains.<locals>.<listcomp>zme/shows/contains?ids=r   r   r,  r+   r1   r,   !current_user_saved_shows_contains  s    z)Spotify.current_user_saved_shows_containsc                 C   s   | j dd||dS )a   Gets a list of the artists followed by the current authorized user

            Parameters:
                - limit - the number of artists to return
                - after - the last artist ID retrieved from the previous
                          request

        zme/followingr   )r   r   afterrv   )r)   r   r1  r+   r+   r,   current_user_followed_artists  s    	   z%Spotify.current_user_followed_artistsc                    s4   g }|dk	r fdd|D } j dd|ddS )z Check if the current user is following certain artists

            Returns list of booleans respective to ids

            Parameters:
                - ids - a list of artist URIs, URLs or IDs
        Nc                    s   g | ]}  d |qS r   r   r   ir1   r+   r,   r     s     z:Spotify.current_user_following_artists.<locals>.<listcomp>me/following/containsr   r   idsr   r   r)   r7  Zidlistr+   r1   r,   current_user_following_artists  s      z&Spotify.current_user_following_artistsc                    s4   g }|dk	r fdd|D } j dd|ddS )z Check if the current user is following certain users

            Returns list of booleans respective to ids

            Parameters:
                - ids - a list of user URIs, URLs or IDs
        Nc                    s   g | ]}  d |qS )r   r   r3  r1   r+   r,   r     s     z8Spotify.current_user_following_users.<locals>.<listcomp>r5  r   r   r6  r   r8  r+   r1   r,   current_user_following_users  s      z$Spotify.current_user_following_usersmedium_termc                 C   s   | j d|||dS )a_   Get the current user's top artists

            Parameters:
                - limit - the number of entities to return (max 50)
                - offset - the index of the first entity to return
                - time_range - Over what time frame are the affinities computed
                  Valid-values: short_term, medium_term, long_term
        zme/top/artists
time_ranger   r   rv   r)   r   r   r=  r+   r+   r,   current_user_top_artists  s       z Spotify.current_user_top_artistsc                 C   s   | j d|||dS )aU   Get the current user's top tracks

            Parameters:
                - limit - the number of entities to return
                - offset - the index of the first entity to return
                - time_range - Over what time frame are the affinities computed
                  Valid-values: short_term, medium_term, long_term
        zme/top/tracksr<  rv   r>  r+   r+   r,   current_user_top_tracks   s       zSpotify.current_user_top_tracksc                 C   s   | j d|||dS )a;   Get the current user's recently played tracks

            Parameters:
                - limit - the number of entities to return
                - after - unix timestamp in milliseconds. Returns all items
                          after (but not including) this cursor position.
                          Cannot be used if before is specified.
                - before - unix timestamp in milliseconds. Returns all items
                           before (but not including) this cursor position.
                           Cannot be used if after is specified
        zme/player/recently-played)r   r1  beforerv   )r)   r   r1  rA  r+   r+   r,   current_user_recently_played/  s    z$Spotify.current_user_recently_playedc                 C   s   |  dd| S )zi Follow one or more artists
            Parameters:
                - ids - a list of artist IDs
        me/following?type=artist&ids=r   r  r)   r7  r+   r+   r,   user_follow_artistsB  s    zSpotify.user_follow_artistsc                 C   s   |  dd| S )ze Follow one or more users
            Parameters:
                - ids - a list of user IDs
        me/following?type=user&ids=r   r  rD  r+   r+   r,   user_follow_usersI  s    zSpotify.user_follow_usersc                 C   s   |  dd| S )zk Unfollow one or more artists
            Parameters:
                - ids - a list of artist IDs
        rC  r   r  rD  r+   r+   r,   user_unfollow_artistsP  s    zSpotify.user_unfollow_artistsc                 C   s   |  dd| S )zg Unfollow one or more users
            Parameters:
                - ids - a list of user IDs
        rF  r   r  rD  r+   r+   r,   user_unfollow_usersW  s    zSpotify.user_unfollow_usersc                 C   s"   t dt | jd|||||dS )a   Get a list of Spotify featured playlists

            .. deprecated::
            This endpoint has been removed by Spotify and is no longer available.

            Parameters:
                - locale - The desired language, consisting of a lowercase ISO
                  639-1 alpha-2 language code and an uppercase ISO 3166-1 alpha-2
                  country code, joined by an underscore.

                - country - An ISO 3166-1 alpha-2 country code.

                - timestamp - A timestamp in ISO 8601 format:
                  yyyy-MM-ddTHH:mm:ss. Use this parameter to specify the user's
                  local time to get results tailored for that specific date and
                  time in the day

                - limit - The maximum number of items to return. Default: 20.
                  Minimum: 1. Maximum: 50

                - offset - The index of the first item to return. Default: 0
                  (the first object). Use with limit to get the next set of
                  items.
        zQYou're using `featured_playlists(...)`, which is marked as deprecated by Spotify.zbrowse/featured-playlists)localer   	timestampr   r   r   r   r   rq   )r)   rJ  r   rK  r   r   r+   r+   r,   featured_playlists^  s    zSpotify.featured_playlistsc                 C   s   | j d|||dS )a   Get a list of new album releases featured in Spotify

            Parameters:
                - country - An ISO 3166-1 alpha-2 country code.

                - limit - The maximum number of items to return. Default: 20.
                  Minimum: 1. Maximum: 50

                - offset - The index of the first item to return. Default: 0
                  (the first object). Use with limit to get the next set of
                  items.
        zbrowse/new-releasesr   r   r   rv   )r)   r   r   r   r+   r+   r,   new_releases  s       zSpotify.new_releasesc                 C   s   | j d| ||dS )a   Get info about a category

            Parameters:
                - category_id - The Spotify category ID for the category.

                - country - An ISO 3166-1 alpha-2 country code.
                - locale - The desired language, consisting of an ISO 639-1 alpha-2
                  language code and an ISO 3166-1 alpha-2 country code, joined
                  by an underscore.
        browse/categories/)r   rJ  rv   )r)   category_idr   rJ  r+   r+   r,   category  s
    zSpotify.categoryc                 C   s   | j d||||dS )an   Get a list of categories

            Parameters:
                - country - An ISO 3166-1 alpha-2 country code.
                - locale - The desired language, consisting of an ISO 639-1 alpha-2
                  language code and an ISO 3166-1 alpha-2 country code, joined
                  by an underscore.

                - limit - The maximum number of items to return. Default: 20.
                  Minimum: 1. Maximum: 50

                - offset - The index of the first item to return. Default: 0
                  (the first object). Use with limit to get the next set of
                  items.
        zbrowse/categories)r   rJ  r   r   rv   )r)   r   rJ  r   r   r+   r+   r,   
categories  s    zSpotify.categoriesc                 C   s&   t dt | jd| d |||dS )a   Get a list of playlists for a specific Spotify category

            .. deprecated::
            This endpoint has been removed by Spotify and is no longer available.

            Parameters:
                - category_id - The Spotify category ID for the category.

                - country - An ISO 3166-1 alpha-2 country code.

                - limit - The maximum number of items to return. Default: 20.
                  Minimum: 1. Maximum: 50

                - offset - The index of the first item to return. Default: 0
                  (the first object). Use with limit to get the next set of
                  items.
        zQYou're using `category_playlists(...)`, which is marked as deprecated by Spotify.rP  r   rN  rL  )r)   rQ  r   r   r   r+   r+   r,   category_playlists  s    
zSpotify.category_playlistsc                    s   t dt t|d}|r6d fdd|D |d< |rHd||d< |rhd fdd|D |d	< |rt||d
< dD ]*}dD ] }	|	| }
|
|kr||
 ||
< qqx jd|S )ak   Get a list of recommended tracks for one to five seeds.
            (at least one of `seed_artists`, `seed_tracks` and `seed_genres`
            are needed)

            .. deprecated::
            This endpoint has been removed by Spotify and is no longer available.

            Parameters:
                - seed_artists - a list of artist IDs, URIs or URLs
                - seed_tracks - a list of track IDs, URIs or URLs
                - seed_genres - a list of genre names. Available genres for
                                recommendations can be found by calling
                                recommendation_genre_seeds

                - country - An ISO 3166-1 alpha-2 country code. If provided,
                            all results will be playable in this country.

                - limit - The maximum number of items to return. Default: 20.
                          Minimum: 1. Maximum: 100

                - min/max/target_<attribute> - For the tuneable track
                    attributes listed in the documentation, these values
                    provide filters and targeting on results.
        zNYou're using `recommendations(...)`, which is marked as deprecated by Spotify.)r   r   c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     z+Spotify.recommendations.<locals>.<listcomp>seed_artistsseed_genresc                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r     s     seed_tracksr|   )ZacousticnessZdanceabilityZduration_msZenergyZinstrumentalnesskeyZlivenessZloudnessmodeZ
popularityZspeechinessZtempoZtime_signatureZvalence)Zmin_Zmax_Ztarget_recommendations)rZ  )r   r   r   rR   r   rq   )r)   rU  rV  rW  r   r   rp   rH   	attributer   paramr+   r1   r,   rZ    s.    !
zSpotify.recommendationsc                 C   s   t dt | dS )z Get a list of genres available for the recommendations function.

            .. deprecated::
            This endpoint has been removed by Spotify and is no longer available.
        zYYou're using `recommendation_genre_seeds(...)`, which is marked as deprecated by Spotify.z%recommendations/available-genre-seedsrL  r1   r+   r+   r,   recommendation_genre_seeds,  s
    z"Spotify.recommendation_genre_seedsc                 C   s&   t dt | d|}| d| S )z Get audio analysis for a track based upon its Spotify ID

            .. deprecated::
            This endpoint has been removed by Spotify and is no longer available.

            Parameters:
                - track_id - a track URI, URL or ID
        zMYou're using `audio_analysis(...)`, which is marked as deprecated by Spotify.rz   zaudio-analysis/r   )r)   r   r   r+   r+   r,   audio_analysis9  s    	zSpotify.audio_analysisc                    sp   t dt t|tr2 d|} d| }n& fdd|D } dd| }d|krh|d S |S dS )	a+   Get audio features for one or multiple tracks based upon their Spotify IDs

            .. deprecated::
            This endpoint has been removed by Spotify and is no longer available.

            Parameters:
                - tracks - a list of track URIs, URLs or IDs, maximum: 100 ids
        zMYou're using `audio_features(...)`, which is marked as deprecated by Spotify.rz   zaudio-features/?ids=c                    s   g | ]}  d |qS r   r   r   r1   r+   r,   r   ]  s     z*Spotify.audio_features.<locals>.<listcomp>r   audio_featuresN)r   r   r   r#   r  r~   rq   r   )r)   r   Ztrackidri   r   r+   r1   r,   r_  J  s    	
zSpotify.audio_featuresc                 C   s
   |  dS )z1 Get a list of user's available devices.
        zme/player/devicesrv   r1   r+   r+   r,   devicesf  s    zSpotify.devicesc                 C   s   | j d||dS )z Get information about user's current playback.

            Parameters:
                - market - an ISO 3166-1 alpha-2 country code.
                - additional_types - `episode` to get podcast track information
        	me/playerr  rv   r  r+   r+   r,   current_playbackk  s    zSpotify.current_playbackc                 C   s   | j d||dS )z Get user's currently playing track.

            Parameters:
                - market - an ISO 3166-1 alpha-2 country code.
                - additional_types - `episode` to get podcast track information
        r  r  rv   r  r+   r+   r,   currently_playingt  s    zSpotify.currently_playingc                 C   s   |g|d}| j d|dS )ac   Transfer playback to another device.
            Note that the API accepts a list of device ids, but only
            actually supports one.

            Parameters:
                - device_id - transfer playback to this device
                - force_play - true: after transfer, play. false:
                               keep current state.
        )Z
device_idsZplayra  r   r  )r)   	device_idZ
force_playrK   r+   r+   r,   transfer_playback~  s    
zSpotify.transfer_playbackc                 C   s   |dk	r|dk	rt d dS |dk	r>t|ts>t d dS i }|dk	rR||d< |dk	rb||d< |dk	rr||d< |dk	r||d< | j| d||d	S )
a   Start or resume user's playback.

            Provide a `context_uri` to start playback of an album,
            artist, or playlist.

            Provide a `uris` list to start playback of one or more
            tracks.

            Provide `offset` as {"position": <int>} or {"uri": "<track uri>"}
            to start playback at a particular offset.

            Parameters:
                - device_id - device target for playback
                - context_uri - spotify context uri to play
                - uris - spotify track uris
                - offset - offset into context by index or track
                - position_ms - (optional) indicates from what position to start playback.
                                Must be a positive number. Passing in a position that is
                                greater than the length of the track will cause the player to
                                start playing the next song.
        Nz,Specify either context uri or uris, not bothzURIs must be a listcontext_urir  r   position_mszme/player/playr   )rV   warningr#   r   rt   _append_device_id)r)   rd  rf  r  r   rg  rK   r+   r+   r,   start_playback  s&    


 zSpotify.start_playbackc                 C   s   |  | d|S )zr Pause user's playback.

            Parameters:
                - device_id - device target for playback
        zme/player/pause)rt   ri  r)   rd  r+   r+   r,   pause_playback  s    zSpotify.pause_playbackc                 C   s   |  | d|S )z Skip user's playback to next track.

            Parameters:
                - device_id - device target for playback
        zme/player/nextrr   ri  rk  r+   r+   r,   
next_track  s    zSpotify.next_trackc                 C   s   |  | d|S )z Skip user's playback to previous track.

            Parameters:
                - device_id - device target for playback
        zme/player/previousrm  rk  r+   r+   r,   previous_track  s    
zSpotify.previous_trackc                 C   s0   t |tstd dS | | d| |S )z Seek to position in current track.

            Parameters:
                - position_ms - position in milliseconds to seek to
                - device_id - device target for playback
        zPosition_ms must be an integerNzme/player/seek?position_ms=r#   intrV   rh  rt   ri  )r)   rg  rd  r+   r+   r,   
seek_track  s    

 zSpotify.seek_trackc                 C   s2   |dkrt d dS | | d| | dS )z Set repeat mode for playback.

            Parameters:
                - state - `track`, `context`, or `off`
                - device_id - device target for playback
        )rz   contextoffzInvalid stateNzme/player/repeat?state=)rV   rh  rt   ri  r)   staterd  r+   r+   r,   repeat  s    
 zSpotify.repeatc                 C   sR   t |tstd dS |dk s(|dkr6td dS | | d| | dS )z Set playback volume.

            Parameters:
                - volume_percent - volume between 0 and 100
                - device_id - device target for playback
        zVolume must be an integerNr   r   z+Volume must be between 0 and 100, inclusivez me/player/volume?volume_percent=rp  )r)   Zvolume_percentrd  r+   r+   r,   volume  s    


zSpotify.volumec                 C   s@   t |tstd dS t| }| | d| | dS )z Toggle playback shuffling.

            Parameters:
                - state - true or false
                - device_id - device target for playback
        zstate must be a booleanNzme/player/shuffle?state=)r#   r  rV   rh  r  lowerrt   ri  ru  r+   r+   r,   shuffle  s    

 zSpotify.shufflec                 C   s
   |  dS )z Gets the current user's queue zme/player/queuerv   r1   r+   r+   r,   queue  s    zSpotify.queuec                 C   s6   |  d|}d| }|dk	r,|d| 7 }| |S )a   Adds a song to the end of a user's queue

            If device A is currently playing music, and you try to add to the queue
            and pass in the id for device B, you will get a
            'Player command failed: Restriction violated' error
            I therefore recommend leaving device_id as None so that the active device is targeted

            :param uri: song uri, id, or url
            :param device_id:
                the id of a Spotify device.
                If None, then the active device is used.

        rz   zme/player/queue?uri=N&device_id=)r   rr   )r)   r   rd  r  r+   r+   r,   add_to_queue  s
    
zSpotify.add_to_queuec                 C   s
   |  dS )z Get the list of markets where Spotify is available.
            Returns a list of the countries in which Spotify is available, identified by their
            ISO 3166-1 alpha-2 country code with additional country codes for special territories.
        r   rv   r1   r+   r+   r,   available_markets1  s    zSpotify.available_marketsc                 C   s.   |r*d|kr|d| 7 }n|d| 7 }|S )zr Append device ID to API path.

            Parameters:
                - device_id - device id to append
        ?r|  z?device_id=r+   )r)   pathrd  r+   r+   r,   ri  8  s
    zSpotify._append_device_idc                 C   s   t tj|}|d k	r>| }|d |kr6tddd|d S t tj|}|d k	r|| }|d |krttddd|d S t tj|d k	r|S tdddd S )Nr   i  rQ   zUnexpected Spotify URI type.idzUnexpected Spotify URL type.zUnsupported URL / URI.)rer   r   _regex_spotify_uri	groupdictr   _regex_spotify_url_regex_base62)r)   r   r  Z	uri_matchZuri_match_groupsZ	url_matchZurl_match_groupsr+   r+   r,   r~   E  s    zSpotify._get_idc                 C   s*   |  |r|S d| d | || S d S )Nzspotify::)_is_urir~   )r)   r   r  r+   r+   r,   r   ]  s    
zSpotify._get_uric                 C   s   t tj|d k	S r.   )r  r   r   r  )r)   r   r+   r+   r,   r  c  s    zSpotify._is_uric              	   C   s  |r$||kr$|}t d| dt tt}dd |dD }d}	|D ]}
| jd|||||
d}|D ]}|| ||
 |< t||
 | d	 |kr||
 | d	 d | ||
 | d	< |	t||
 | d	 7 }	|rf|||	 krf||	 }qf|rH|	|krH|  S qH|S )
Nz!limit was auto-adjusted to equal z$ as it must not be higher than totalc                 S   s   g | ]}|d  qS )r   r+   )r   	item_typer+   r+   r,   r   n  s     z4Spotify._search_multiple_markets.<locals>.<listcomp>r   r   r   r   r
  )r   r   r   r   rR   splitrq   len)r)   r   r   r   r   r   r9   ri   Z
item_typescountr   rx   r  r+   r+   r,   r   f  s8         

z Spotify._search_multiple_marketsc                 C   s2   |  d|}d| }|r(|d| 7 }| |S )z Get Spotify catalog information for a single audiobook identified by its unique
        Spotify ID.

        Parameters:
        - id - the Spotify ID for the audiobook
        - market - an ISO 3166-1 alpha-2 country code.
        	audiobookaudiobooks/r   r}   )r)   r  r|   audiobook_idr  r+   r+   r,   get_audiobook  s
    
zSpotify.get_audiobookc                    s>    fdd|D }dd | }|r4|d| 7 } |S )z Get Spotify catalog information for multiple audiobooks based on their Spotify IDs.

        Parameters:
        - ids - a list of Spotify IDs for the audiobooks
        - market - an ISO 3166-1 alpha-2 country code.
        c                    s   g | ]}  d |qS )r  r   )r   r  r1   r+   r,   r     s     z*Spotify.get_audiobooks.<locals>.<listcomp>zaudiobooks?ids=r   r   r  )r)   r7  r|   Zaudiobook_idsr  r+   r1   r,   get_audiobooks  s
    zSpotify.get_audiobooksc                 C   s>   |  d|}d| d| d| }|r4|d| 7 }| |S )u7   Get Spotify catalog information about an audiobook’s chapters.

        Parameters:
        - id - the Spotify ID for the audiobook
        - market - an ISO 3166-1 alpha-2 country code.
        - limit - the maximum number of items to return
        - offset - the index of the first item to return
        r  r  z/chapters?limit=z&offset=r   r}   )r)   r  r|   r   r   r  r  r+   r+   r,   get_audiobook_chapters  s
    	zSpotify.get_audiobook_chapters)NN)NN)NN)NN)N)N)NNNr   r   )r   )N)r   r   N)N)N)N)r   r   N)N)N)r   r   rz   N)r   r   rz   NN)r   r   )NNr   )Nr   r   Nr   )Nr   r   Nr   )NNN)NNNr   r   N)r   r   )TFr   )NNNN)N)N)r   N)N)N)NNNN)N)r   N)N)N)T)Nr   )r   r   N)r   r   N)N)N)N)r   r   N)N)N)N)r   r   N)r   N)N)N)r   r   r;  )r   r   r;  )r   NN)NNNr   r   )Nr   r   )NN)NNr   r   )NNr   r   )NNNr   N)NN)NN)T)NNNNN)N)N)N)N)N)N)N)N)N)N)Nr   r   )__name__
__module____qualname____doc__r=   r   r   r  r  r  r-   r/   propertyr   setterr4   r'   rG   rl   rq   rr   rs   rt   ru   ry   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r"  r#  r$  r%  r(  r)  r*  r+  r.  r/  r0  r2  r9  r:  r?  r@  rB  rE  rG  rH  rI  rM  rO  rR  rS  rT  rZ  r]  r^  r_  r`  rb  rc  re  rj  rl  rn  ro  rr  rw  rx  rz  r{  r}  r~  ri  r~   r   r  r   r  r  r  r+   r+   r+   r,   r      s  J
G

J
        
%     
#    
	     
#   
!

 
$

)   
 
 
 




	

    
    
        )      "    K	
        +
")r  __all__rT   loggingr  r   collectionsr   r$   Zspotipy.exceptionsr   Zspotipy.utilr   r   	getLoggerr  rV   r   r+   r+   r+   r,   <module>   s   
