The goal is to utilize the Wolfram SQL paclet to explore and analyze data from the Spotify Web API. By leveraging the Spotify Web API, we can develop applications that interact with Spotify’s streaming service and retrieve various metadata related to its content. I am utilizing the SQLOperators paclet to develop a wrapper for Spotify’s diverse items such as playlists, artists, and albums. This wrapper enables the execution of SQL-like queries, enhancing the user experience and enabling advanced data analytics capabilities. The Spotify Web API documentation can be found at https://developer.spotify.com/documentation/web-api, while the Wolfram SQLOperators paclet can be accessed at https://resources.wolframcloud.com/PacletRepository/resources/DamianCalin/SQLOperators/.

Main Functions


Get Spotify token

You can find detailed instructions for setting up the credentials for accessing the Spotify Web API at https://developer.spotify.com/documentation/web-api.
It’s important to note that the access token provided by the Spotify Web API has a validity period of 1 hour.
After this period, the token expires and needs to be refreshed in order to continue accessing the API.
clientId="cad3114b72c54454a0ea7ee39c2c4f71";​​clientSecret="34eab00174da4eb794525380b0d63c08";​​​​(*tokentobeusedoneachAPIrequest*)​​tokenSpotify=getSpotifyToken[clientId,clientSecret]​​
Out[]=
{Headers{AuthorizationBearer BQBtacyvk0NQ5MbH-CRghgOyMt5winl6XscyWzki28uMtyODXDd1RYxy6ex60MLC5BKPhy1N16YbN03VfR_7md91ClM1S007sPlWEcUq7doJyAFuxfo}}

Demo using Spotify SQL Tables

Install SQL Paclet

The SQLOperators paclet provides a set of SQL operators that enable data exploration using SQL queries within Mathematica.
You can find detailed information on how to use the package and its functionality at the following resource:
​https://resources.wolframcloud.com/PacletRepository/resources/DamianCalin/SQLOperators/
In[]:=
pclt=PacletInstall["DamianCalin/SQLOperators"];​​Needs["DamianCalin`SQLOperators`"]

Retrieve Playlist tracks as SQL Table

You’ll need a playlist Id in order to retrieve playlist tracks.To obtain the playlist ID you need to retrieve it from the Spotify player interface. ​
tbTracks=getSpotifyPlaylistTracksSQL[tokenSpotify,"0GCoBMt4aDfoVtZHAgpbvy"];
Display table as dataset
tbTracks//​​tableSQLAsDataset//​​Dataset[#,DatasetTheme"Minimal"]&
Out[]=
trackId
trackName
artist
artistId
album
releaseDate
albumId
albumImage
durationms
popularity
1WuqBt17J3Kk8ngUOwK1rw
Absolutego
{Boris}
{3EgMK920cIH5aLxFnJ6zSi}
Dear
2017-07-14
49CV8xfmsdSltz74sCTLms
{https://i.scdn.co/image/ab67616d0000b27316a7280e1752e9b66d5f4786,
https://i.scdn.co/image/ab67616d00001e0216a7280e1752e9b66d5f4786,
https://i.scdn.co/image/ab67616d0000485116a7280e1752e9b66d5f4786}
295866
33
0RGtMGYaz9esrHsFiC8TJR
Seer
{Witch}
{6uNOBEATMcW8SSunnKy9a3}
Witch
2006-03-07
5LcBa7FlZORQ1RQRJtlxFz
{https://i.scdn.co/image/ab67616d0000b2739af865f39b7ee8c5d20e9cb6,
https://i.scdn.co/image/ab67616d00001e029af865f39b7ee8c5d20e9cb6,
https://i.scdn.co/image/ab67616d000048519af865f39b7ee8c5d20e9cb6}
477920
47
2v6NdzG616qY6j8FHVnj5n
Barbarian
{Electric Wizard}
{4htjQW3lgIwL6fEJlTOez4}
Dopethrone (Remaster)
2000
2ntG8GB5e2RuOYkSmBo1ij
{https://i.scdn.co/image/ab67616d0000b2730d22d5bbe47f72c19cb85a3a,
https://i.scdn.co/image/ab67616d00001e020d22d5bbe47f72c19cb85a3a,
https://i.scdn.co/image/ab67616d000048510d22d5bbe47f72c19cb85a3a}
389466
40
6rQG8QH1rGoCOeGHdrnYhb
Funeralopolis
{Electric Wizard}
{4htjQW3lgIwL6fEJlTOez4}
Dopethrone (Remaster)
2000
2ntG8GB5e2RuOYkSmBo1ij
{https://i.scdn.co/image/ab67616d0000b2730d22d5bbe47f72c19cb85a3a,
https://i.scdn.co/image/ab67616d00001e020d22d5bbe47f72c19cb85a3a,
https://i.scdn.co/image/ab67616d000048510d22d5bbe47f72c19cb85a3a}
523333
49
1vmJFaauaFMqCtlWsknKwA
Dopethrone
{Electric Wizard}
{4htjQW3lgIwL6fEJlTOez4}
Dopethrone (Remaster)
2000
2ntG8GB5e2RuOYkSmBo1ij
{https://i.scdn.co/image/ab67616d0000b2730d22d5bbe47f72c19cb85a3a,
https://i.scdn.co/image/ab67616d00001e020d22d5bbe47f72c19cb85a3a,
https://i.scdn.co/image/ab67616d000048510d22d5bbe47f72c19cb85a3a}
636226
42
7wO5PMvpLQ0mWv3yAywMLc
Mind Transferal
{Electric Wizard}
{4htjQW3lgIwL6fEJlTOez4}
Dopethrone (Remaster)
2000
2ntG8GB5e2RuOYkSmBo1ij
{https://i.scdn.co/image/ab67616d0000b2730d22d5bbe47f72c19cb85a3a,
https://i.scdn.co/image/ab67616d00001e020d22d5bbe47f72c19cb85a3a,
https://i.scdn.co/image/ab67616d000048510d22d5bbe47f72c19cb85a3a}
896440
28
0SElYK9iouvepQe6zONE7q
Haunter of the Dark
{Cough}
{1jR6DBqtAnOcCPJpzXDvg9}
Still They Pray
2016-06-03
5QfDoahaCCdcEC6EaZDWiH
{https://i.scdn.co/image/ab67616d0000b2731a644924aa1b2afc11016d7c,
https://i.scdn.co/image/ab67616d00001e021a644924aa1b2afc11016d7c,
https://i.scdn.co/image/ab67616d000048511a644924aa1b2afc11016d7c}
470213
35
7up6lmFT6F3k9ld2hsXeht
Boris
{Melvins}
{6aVjo0xHSiuW5hkasoYSR3}
Bullhead
1991-05-03
3hAEZH07Rme4RfmSbd7KMC
{https://i.scdn.co/image/ab67616d0000b273a76fde0835c5a67f9ccf4fa0,
https://i.scdn.co/image/ab67616d00001e02a76fde0835c5a67f9ccf4fa0,
https://i.scdn.co/image/ab67616d00004851a76fde0835c5a67f9ccf4fa0}
514506
37
5u5AyqNqSd9n7SE4GILBPz
Lacrimosa
{Ufomammut}
{105vC0oJ985P5G3g36EosL}
Snailking
2004-05-18
7sIsycnkEImTWqjOTX7i1s
{https://i.scdn.co/image/ab67616d0000b2737d00f7f0205ff929aec0e4a5,
https://i.scdn.co/image/ab67616d00001e027d00f7f0205ff929aec0e4a5,
https://i.scdn.co/image/ab67616d000048517d00f7f0205ff929aec0e4a5}
410800
24
00EPaVrQeghiIct1rICb1H
Let Me Drown
{Ufomammut}
{105vC0oJ985P5G3g36EosL}
Let Me Drown
2023-05-09
0vOEm7fRQ3xQ8oa4hMTrtL
{https://i.scdn.co/image/ab67616d0000b273ea1ab3666f1bb3cf0f72e422,
https://i.scdn.co/image/ab67616d00001e02ea1ab3666f1bb3cf0f72e422,
https://i.scdn.co/image/ab67616d00004851ea1ab3666f1bb3cf0f72e422}
462000
32
rows 1–10 of 110
columns 1–10 of 13

Order by

Artist
tbTracks//​​selectSQL[#,{trackNo,trackName,artist,album}]&//​​orderBySQL[#,{artist}]&//​​tableSQLAsDataset//​​Dataset[#,DatasetTheme"Minimal"]&
Out[]=
trackNo
trackName
artist
album
33
Mind’s Eye
{Acid King}
Beyond Vision
87
Vertigate #1
{Acid King}
The Early Years
89
Drop
{Acid King}
The Early Years
110
Breathing Through Bones
{Anatomy Of Habit}
Black Openings
54
Kali Yuga Blues
{Bardo Pond}
Peace on Venus
55
Tommy Gun Angel
{Bardo Pond}
Lapsed
56
Fir
{Bardo Pond}
Peace on Venus
57
Pick My Brain
{Bardo Pond}
Lapsed
58
Limerick
{Bardo Pond}
Amanita
59
Yellow Turban
{Bardo Pond}
Amanita
rows 1–10 of 110
Popularity in descending order
tbTracks//​​selectSQL[#,{trackNo,trackName,artist,popularity}]&//​​orderBySQL[#,{-popularity}]&//​​tableSQLAsDataset//​​Dataset[#,DatasetTheme"Minimal"]&​​
Out[]=
trackNo
trackName
artist
popularity
48
Holy Wars...The Punishment Due - 2004 Remix
{Megadeth}
72
53
The Pot
{TOOL}
72
44
Forty Six & 2
{TOOL}
71
50
Parabola
{TOOL}
66
47
Ænema
{TOOL}
65
52
Jambi
{TOOL}
65
49
Angel Of Death
{Slayer}
64
45
Hooker With A Penis
{TOOL}
59
51
Ticks & Leeches
{TOOL}
57
46
Pushit
{TOOL}
55
rows 1–10 of 110
Album release date in ascending order

Searches

Tracks with multiple artists
Tracks containing artist
Find tracks released in 2023

Data analysis

Most referenced artists in playlist
Barchart
Tracks counts by year
WordCloud on tracks name
Find duplicate tracks in playlist

Analysing multiple playlists

Common tracks between playlist
Merging 2 playlists

Output format.

Let’s explore the possibility of formatting table output to emulate the display style of the Spotify player

Get Albums

You have the flexibility to modify the default column structure by mapping the columns with the structure provided by the Spotify API.
This allows you to customize the table output to align with the structure of the Spotify API data.
​https://developer.spotify.com/documentation/web-api/reference/get-an-album
Define an assoc of mappig table cols and spotify struct

Get Artists

Obtain the list of artists contained in the playlist

Comments/Suggestions/Donations

CITE THIS NOTEBOOK

Exploring Spotify data using SQL operators paclet​
by Damian Calin​
Wolfram Community, STAFF PICKS, July 4, 2023
​https://community.wolfram.com/groups/-/m/t/2951241