I was trying to get data on spotify tracks in a playlist, and while I was running over the playlist with a script I noticed that some of the values seem odd - for example, one of the songs that I went over, "Somebody Told Me" by The Killers, got a popularity score of 0. When I cross checked on the Spotify Developer console, it said that the popularity score is 75. I also tried this on a few other low scored tracks and their popularity value was also incorrect.
I checked some of the other "normal looking" values and they were correct, so it seems that it only happens for some of the tracks.
Any help/explanation would be appreciated!
Edit: Here's the script in question
import spotipyfrom spotipy.oauth2 import SpotifyClientCredentials# Set up API credentialsclient_id = 'CLIENT-ID-HERE'client_secret = 'CLIENT-SECRET-HERE'client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)# Define playlist IDplaylist_id = 'PLAYLIST-ID-HERE'# Get tracks in the playlistresults = sp.playlist_tracks(playlist_id)tracks = results['items']while results['next']: results = sp.next(results) tracks.extend(results['items'])counter = 0for track in tracks: # Get track details track_info = sp.track(track['track']['id']) track_name = track_info['name'] track_artists = [artist['name'] for artist in track_info['artists']] track_release_date = track_info['album']['release_date'] # Get audio features audio_features = sp.audio_features(track['track']['id'])[0] try: track_genre = sp.artist(track_info['artists'][0]['id'])['genres'][0] except: print(f"Track name: {track_name}") print("----------------------------") continue track_bpm = audio_features['tempo'] track_energy = audio_features['energy'] track_danceability = audio_features['danceability'] track_loudness = audio_features['loudness'] track_valence = audio_features['valence'] track_length = audio_features['duration_ms'] / 1000 track_acousticness = audio_features['acousticness'] track_speechiness = audio_features['speechiness'] track_popularity = track_info['popularity'] # Print track information print(f"Track name: {track_name}") print(f"Artists: {', '.join(track_artists)}") print(f"Genre: {track_genre}") print(f"Release date: {track_release_date}") print(f"BPM: {track_bpm}") print(f"Energy: {track_energy}") print(f"Danceability: {track_danceability}") print(f"Loudness: {track_loudness}") print(f"Valence: {track_valence}") print(f"Length: {track_length}") print(f"Acousticness: {track_acousticness}") print(f"Speechiness: {track_speechiness}") print(f"Popularity: {track_popularity}") print("----------------------------") counter+=1
Another thing I noticed; I made a new playlist with some of the problematic songs and the popularity was accurate. I tried adding more songs, and when I passed the 10 song mark some songs after it had the wrong popularity.