Spotipy: Now playing example

Created on 29 Oct 2017  Â·  8Comments  Â·  Source: plamere/spotipy

Could you provide a example py script how to obtain infos about the song currently played by the user?

Most helpful comment

Here is a quick one:

import spotipy
import spotipy.util as util

scope = 'user-read-currently-playing'
# scope = 'user-read-playback-state'
# works as well

token = util.prompt_for_user_token(username, scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)

spotify = spotipy.Spotify(auth=token)
current_track = spotify.current_user_playing_track()

print(current_track)

All 8 comments

Here is a quick one:

import spotipy
import spotipy.util as util

scope = 'user-read-currently-playing'
# scope = 'user-read-playback-state'
# works as well

token = util.prompt_for_user_token(username, scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)

spotify = spotipy.Spotify(auth=token)
current_track = spotify.current_user_playing_track()

print(current_track)

Does this use the local client? It should be compatible with the native windows/linux/mac app and the windows store version

If yes, whats the best way to ask the user for his auth info? and would spotify.current_user_playing_artist() give back a list of artists or just a comma seperated string?

I just tried running that same script with my own credentials added and I got an error returned: 'Spotify' object has no attribute 'current_user_playing_track'

Any ideas why that might be happening?

It's probably because of issue https://github.com/plamere/spotipy/issues/211

This is still happening to me even with 2.4.4 installed. Funny enough when I compile in my text editor(Atom) it works fine. But when I run this from the terminal, it gives me that same error that @joeborrello got.

@mitchellpalermo if you run the code spotipy.VERSION does it return 2.0.1 or 2.4.4? Even when it pip says you've install 2.4.4, its actually 2.0.1 This is what fixed it for me

I just got spotify from https://github.com/plamere/spotipy/archive/master.zip but

>>> import spotipy

>>> spotipy.VERSION

'2.0.1'

Closing as everything looks answered or depends on another issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fortyTwo102 picture fortyTwo102  Â·  4Comments

CMoore97 picture CMoore97  Â·  3Comments

DylanMeeus picture DylanMeeus  Â·  4Comments

Kurchunk picture Kurchunk  Â·  3Comments

StefanRickli picture StefanRickli  Â·  3Comments