This page describes the parts of the backend that are currently in use.
The backend gets a call from the frontend using a Spotify Artist URI or Spotify Album Uri:
# Artist call
get_artist_results('6olE6TJLqED3rqDCT0FyPh')
# Album call
get_album_content('spotify:album:6yaiubHHJy8N8QcHy3julo') # Spotify album
get_album_content('f1afec0b-26dd-3db5-9aa1-c91229a74a24') # Musicbrainz album
The following is returned for the specified parameters
- get_artist_results('6olE6TJLqED3rqDCT0FyPh') result
- get_album_content('spotify:album:1KVGLuPtrMrLlyy4Je6df7') result
- get_album_content('f1afec0b-26dd-3db5-9aa1-c91229a74a24') result
Artist call
When a call for artist data is made from the frontend the following happens:
- The Spotify artist URI is passed down on the get_artist_results function in data_merger.py
Here the following steps are taken:
- data is retrieved from Spotify for specified artist
- Spotify API calls are done using the spotify_api function in spotify.py
- for each album retrieved the following items are added as dictionary items to the list album_list:
- name
- release_date
- amount_songs
- spotify uri
- spotify url
- image (url)
- for the artist the following items are added to the dictionary artist_dict:
- name
- genres
- popularity
- image
- albums (retrieved from previously made list album_list)
- artist_dict is passed on
- data is retrieved from Musicbrainz for specified artist
- Musicbrainz API calls are done using the musicbrainz_api function in musicbrainz.py based on the Spotify artist URI
- At first, the Spotify artist URI is converted into the corresponding Musicbrainz artist URI (also called MBID). This is done using the get_artist_mbid function in spotify2mb.py
- get_artist_mbid searches for a specified Spotify artist URI using the Musicbrainz API. It returns the corresponding artist MBID or an error if none or multiple are found
- for each album retrieved the following items are added as dictionary items to the list album_list:
- name
- release_date
- musicbrainz uri
- image and amount_songs are set to None as Musicbrainz does not return this kind of data
- album_list is passed on
- duplicate album entries are removed from Spotify data. Data is considered duplicate when the name and release date match
- next an identifier list is made based on the cleaned Spotify album entries. For each entry the name and release date are added to the list as dictionary items
- this identifier list is checked against the Musicbrainz album entries. If an album is already in the Spotify data, only the Musicbrainz album Identier is added to the relevant Spotify album entry. If the Musicbrainz album is not in the Spotify entries, the album is added to the list musicbrainz_unique_albums_list.
- now the cleaned entries from Spotify and unique entries from Musicbrainz are combined
- next the combined data is sorted based on release date
- after this the albums list (= the combined data) replaces the original artist album list retrieved from Spotify. The result is saved in artist_dict
- a weight function is added for each album that tells something about the completeness of the data:
- the amount of songs is multiplied by 0,01. This makes it so that similar album releases with more songs get greater focus. For example a Deluxe version is generally set higher than the non Deluxe version because of the amount of songs.
- If a Spotify URI exists 1 is added
- If a Musicbrainz URI (also called MBID) exists 1 is added
- If an image link exists 2 is added
- If the release date consists of a year, month and date (yyyy-mm-dd) 1 is added
- If the release date only consists of a year (yyyy) 0,5 is added
- The total sum is added to the relevant album entry as relevance_score
- Last but not least, the release date entry of the albums is converted to unix time where if only a year is known the album release date is set to in the middle of that year