spotifylibspotify

What data can I save from the Spotify API?


I'm building a website and I'm using the Spotify API as a music library. I would like to add more filters and order options to search tracks than the API allows me to so I was wondering what track/song data can I save to my database from the API, like artist name or popularity.

I would like to save: Name, Artists, Album and some other stuff. Is that possible or is it against the terms and conditions?


Solution

  • Yes, it is possible.

    Data is stored in Spotify API in endpoints.

    Spotify API endpoint reference here.

    Each endpoint deals with the specific kind of data being requested by the client (you).

    I'll give you one example. The same logic applies for all other endpoints.

    import requests
    
       """
       Import library in order to make api calls.
       Alternatively, ou can also use a wrapper like "Spotipy" 
       instead of requesting directely.
       """
    
    # hit desired endpoint
    SEARCH_ENDPOINT = 'https://api.spotify.com/v1/search'
    
    # define your call
    def search_by_track_and_artist(artist, track):
    
        path = 'token.json' # you need to get a token for this call
                            # endpoint reference page will provide you with one
                            # you can store it in a file
    
        with open(path) as t:
            token = json.load(t)
    
        # call API with authentication
        myparams = {'type': 'track'}
        myparams['q'] = "artist:{} track:{}".format(artist,track)
        resp = requests.get(SEARCH_ENDPOINT, params=myparams, headers={"Authorization": "Bearer {}".format(token)})
        return resp.json()
    

    try it:

    search_by_track_and_artist('Radiohead', 'Karma Police')
    

    Store the data and process it as you wish. But you must comply with Spotify terms in order to make it public.

    sidenote: Spotipy docs.