Retrieving Spotify playlist follower count in Python

954 views Asked by At

I'd like to retrieve the follower count of my Spotify playlist using Python. I've been searching https://developer.spotify.com/documentation/web-api/reference-beta/#category-playlists but haven't found a way to do so yet. However, I found a working code on how to retrieve the track IDs of a playlist, how could I tweak it to get the followers instead?

def getTrackIDs(user, playlist_id):
    ids = []
    playlist = sp.user_playlist(user, playlist_id)
    for item in playlist['tracks']['items']:
        track = item['track']
        ids.append(track['id'])
    return ids

ids = getTrackIDs('User', 'Playlist_Id')

print(len(ids))
print(ids)
1

There are 1 answers

0
GLJ On

Take a look at the playlist object that should be returned by getting a playlist.

https://developer.spotify.com/documentation/web-api/reference/object-model/#playlist-object-full.

It has the followers property which is a followers object which is located here

https://developer.spotify.com/documentation/web-api/reference/object-model/#followers-object.

The followers object contains the total property, which should be what you are looking for.

Although I cannot run your code, I imagine the result should look like the following. Let me know if this works for you (I can't run the code).

def getPlaylistFollowerCount(user, playlist_id):
    playlist = sp.user_playlist(user, playlist_id)
    return playlist['followers']['total']