2

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 traks than the api allows me to so I was wondering what track/song data can I save to my DB 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?

Thanks in advance!

1 Answers1

2

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.

piet.t
  • 11,718
  • 21
  • 43
  • 52
8-Bit Borges
  • 9,643
  • 29
  • 101
  • 198
  • Thanks for that answer but I was wondering about the terms and conditions. Do they allow you to save their data? – Francesc Edo May 03 '18 at 20:26
  • This is helpful. I've looked through the docs and didn't see anything that explicitly prevented me from saving data. I did read a few times that you should clean up data if a user revokes access. I was hesitant though thinking that there MUST be some kind of restriction. My use case is to save info on playlists I've generated for users, so I know not to add previously added songs, and to limit API calls. – mikeymurph77 May 14 '18 at 17:41