Get Track release date in Spotify
Asked Answered
W

2

7

I need to get actual Spotify release date of the track (the date, when track appeared on the service). Is it possible to get this date from Spotify API?

Welldisposed answered 22/11, 2016 at 8:38 Comment(0)
D
7

You can retrieve a track's release date from the album it's part of. Use the Get an Album endpoint and read the release_date attribute. Note that the format of the attribute will depend on the value in the release_date_precision attribute.

Edit: The date when the album appeared on Spotify isn't exposed in the API.

Diocese answered 11/12, 2016 at 12:21 Comment(1)
Yeah, but I guess it's a release of the Album worldwide but not the date when it appeared in spotify.Welldisposed
S
0

I was looking for something like this and I got it with Spotipy, a package from Python. I don't now if this is the best coding, but it works very well.

I used two packages from Python: spotipy to get the data from Spotify and pandas to beutify the output information.

For more information about Spotipy integration with Spotify, I recommend you read this article on Medium.

Here's the code:

import spotipy
import pandas as pd
from spotipy.oauth2 import SpotifyClientCredentials

CLIENT_ID = YOUR_CLIENT_ID
CLIENT_SECRET = YOUR_CLIENT_SECRET
MY_USERNAME = YOUR_SPOTIFY_USERNAME
MY_PLAYLIST_ID = YOUR_SPOTIFY_PLAYLIST_ID

sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id=CLIENT_ID, client_secret=CLIENT_SECRET))


def get_playlist_tracks(username, playlist_id):
    results = sp.user_playlist_tracks(username, playlist_id)
    tracks = results['items']
    while results['next']:
        results = sp.next(results)
        tracks.extend(results['items'])
    return tracks


all_tracks = get_playlist_tracks(MY_USERNAME, MY_PLAYLIST_ID)

all_track_names = []
for i in all_tracks:
    all_track_names.append([i['track']['name'], i['track']['album']['release_date'][:4]])

df = pd.DataFrame(all_track_names, columns=['Track', 'Released'])
print(df)

You just need to install the two packages that I mentioned before and change the values from CLIENT_ID, CLIENT_SECRET, MY_USERNAME and MY_PLAYLIST_ID.

I hope you enjoy it.

Souse answered 25/12, 2023 at 20:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.