Get 'Spotify' API Multiple Information.
DSpoty
R Package to Get Multiple Information from Spotify API.
Installation
devtools::install_github('https://github.com/AlbertoAlmuinha/DSpoty')
Authentication
You need to get your Spotify API Client ID and Secret ID. You can get yours here . The best way to authenticate is to set your ID’s to system environment variables (client_id and secret_id). If you prefer, you can use your ID’s en each function to call the function get_spotify_access_token, but it’s not recomendable.
Sys.setenv(client_id = 'client_id')
Sys.setenv(client_secret = 'client_secret')
access_token <- DSpoty::get_spotify_access_token()
Usage
Get Artist Information
You can get an artist Spotify information with the function get_artists. This function returns data like the name of the artist, links to open in spotify, popularity, number of followers or musical genre.
artist <- get_artist('Arctic Monkeys')
artist_name | artist_uri | artist_img | num_followers | spotify_url | popularity | musical_genre |
---|---|---|---|---|---|---|
Arctic Monkeys | 7Ln80lUS6He07XvHI8qqHH | https://i.scdn.co/image/ed0552e9746ed2bbf04ae4bcb5525700ca31522d | 8780891 | 86 | garage_rock-modern_rock-permanent_wave-rock-sheffield_indie |
Another option is to search artists by musical genre. You can choose the number of artists returned and the year. The information returned is the same that with get_artists function.
artists_by_genre <- get_artists_by_genre('rock', limit = 20, year = 2019)
artist_name | artist_uri | artist_img | num_followers | spotify_url | popularity | musical_genre |
---|---|---|---|---|---|---|
Queen | 1dfeR4HaWDbWqFHLkxsg1d | https://i.scdn.co/image/b040846ceba13c3e9c125d68389491094e7f2982 | 22469906 | 93 | glam_rock-rock | |
The Beatles | 3WrFJ7ztbogyGnTHbHJFl2 | https://i.scdn.co/image/6b2a709752ef9c7aaf0d270344157f6cd2e0f1a7 | 14688077 | 91 | british_invasion-merseybeat-psychedelic_rock-rock | |
Twenty One Pilots | 3YQKmKGau1PzlVlkL1iodx | https://i.scdn.co/image/19e8f3bc875b7a4b9cf0041a5ee696c4be5478aa | 15682408 | 88 | modern_rock-rock | |
Maroon 5 | 04gDigrS5kc9YWfZHwBETP | https://i.scdn.co/image/608c7b23420c9556a7eabd9097f7e171a91d3871 | 21450933 | 94 | pop-pop_rock | |
Imagine Dragons | 53XhwfbYqKCa1cC15pYq2q | https://i.scdn.co/image/01b36ca0f45f2f15117022a2754287a6ca1acdcc | 24260851 | 92 | modern_rock |
Finally, you can search related artists. In this case, you need the artist ID (and not the name) to use the function. You can get this information from the function get_artists or artists_by_genre. You will get the top 20 related artist.
related_artists<-get_related_artists(artist_uri = artist$artist_uri)
artist_name | artist_uri | popularity | url_img |
---|---|---|---|
The Kooks | 1GLtl8uqKmnyCWxHmw9tL4 | 73 | https://i.scdn.co/image/0a3dfed5bce0e6d14703011ec52a42ae719c0d4b |
Alex Turner | 1ctkBmvz80MGyi72Ix055S | 66 | https://i.scdn.co/image/ab67616d0000b273672951d44a35cb08092f2c1f |
The Last Shadow Puppets | 2Z7UcsdweVlRbAk5wH5fsf | 65 | https://i.scdn.co/image/1e721c9502da1663fe9dd0b9f8a90519546f0a9f |
Blossoms | 22RISwgVJyZu9lpqAcv1F5 | 66 | https://i.scdn.co/image/b0722b13be43495b793d3911ef90403d62eb5d7b |
Kasabian | 11wRdbnoYqRddKBrpHt4Ue | 69 | https://i.scdn.co/image/8ef02a528dfa5496a410aa80e8b0316574ca95b7 |
Get Albums Information
You can get the whole discography of an artist in few seconds with the function get_artists_albums. You must select one of the next options to the parameter album_type (default option is album):
- album
- single
- appears_on
- compilation
albums <- get_artist_albums('Arctic Monkeys')
albums <- get_artist_albums('Arctic Monkeys', album_type = 'appears_on', limit = 20)
album_uri | album_name | rel_album_artista | album_type | album_img | album_url | release_date | release_date_precision | total_tracks | available_markets | popularity |
---|---|---|---|---|---|---|---|---|---|---|
1nXwgYOolvutEaVWfGbP4w | Isles Of Wonder: Music For The Opening Ceremony Of The London 2012 Olympic Games | appears_on | compilation | https://i.scdn.co/image/852299f998fe2b5c1e34450600c5bc8e4d432eef | 2012-01-01 | day | 36 | CA | 14 | |
1GvWtv7m3NX1vZ1Lk4i13M | The BRIT Awards 2012 | appears_on | compilation | https://i.scdn.co/image/209b4066a831af140c232d4bf6a3eadab013945d | 2012-01-01 | day | 61 | GB | 29 | |
5GaeDKlnZggETclP0Y3FfE | Domino Sampler ’11 | appears_on | compilation | https://i.scdn.co/image/ab67616d0000b273d20f68791889d57d61a8400e | 2011-12-20 | day | 18 | CA | 9 | |
4jqIQ4srPIBcTcPdGFxdGF | All The Rage | appears_on | compilation | https://i.scdn.co/image/ab67616d0000b2737c4f2e686a2fa77227fb5b53 | 2008-02-01 | day | 15 | AD | 29 | |
3Vx8n3WCI0s0l2mvS0IMg3 | Again & Again | appears_on | single | https://i.scdn.co/image/ab67616d0000b273549cf94db1362c3939806e7e | 2008 | year | 4 | JP | 0 |
Get Tracks Information
Firstly, you can get all the tracks of an artist. This can be done with the next function:
tracks <- get_artist_tracks('Arctic Monkeys')
track_name | track_uri | album_uri | artist_uri | disc_number | track_duration_ms | explicit | spotify_url | track_mp3_30s | track_number |
---|---|---|---|---|---|---|---|---|---|
Star Treatment | 0FgNSsaSZTvbLXUumSO8LQ | 1jeMiSeSnNS0Oys375qegp | 7Ln80lUS6He07XvHI8qqHH | 1 | 354640 | FALSE | 1 | ||
One Point Perspective | 2AKwcNHeGAqCpD6etK425X | 1jeMiSeSnNS0Oys375qegp | 7Ln80lUS6He07XvHI8qqHH | 1 | 208640 | FALSE | 2 | ||
American Sports | 0mQiDbYxHElUp1eNpLZXaY | 1jeMiSeSnNS0Oys375qegp | 7Ln80lUS6He07XvHI8qqHH | 1 | 158040 | FALSE | 3 | ||
Tranquility Base Hotel & Casino | 7co8zvT6HJuyT81IDukyID | 1jeMiSeSnNS0Oys375qegp | 7Ln80lUS6He07XvHI8qqHH | 1 | 212093 | TRUE | 4 | ||
Golden Trunks | 3NmndGYOIYocA5OTHMVoaw | 1jeMiSeSnNS0Oys375qegp | 7Ln80lUS6He07XvHI8qqHH | 1 | 173626 | FALSE | 5 |
You can also get all the tracks features information (like danceability, mode, acousticness, speechness, valence, loudness…) for an artist:
features <- get_artist_tracks_features('Arctic Monkeys')
track_uri | danceability | energy | key | loudness | mode | speechiness | acousticness | instrumentalness | liveness | valence | tempo | time_signature | popularity |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0FgNSsaSZTvbLXUumSO8LQ | 0.581 | 0.767 | 7 | -5.026 | 0 | 0.0527 | 0.24300 | 1.31e-03 | 0.141 | 0.6730 | 120.070 | 4 | 60 |
2AKwcNHeGAqCpD6etK425X | 0.714 | 0.585 | 8 | -4.570 | 1 | 0.0419 | 0.05700 | 4.44e-03 | 0.144 | 0.8420 | 77.104 | 4 | 59 |
0mQiDbYxHElUp1eNpLZXaY | 0.372 | 0.865 | 7 | -4.288 | 0 | 0.0513 | 0.00169 | 2.93e-03 | 0.127 | 0.5940 | 176.689 | 3 | 53 |
7co8zvT6HJuyT81IDukyID | 0.584 | 0.835 | 9 | -4.326 | 0 | 0.0297 | 0.04110 | 1.47e-02 | 0.199 | 0.7810 | 142.200 | 4 | 60 |
3NmndGYOIYocA5OTHMVoaw | 0.492 | 0.564 | 2 | -5.811 | 1 | 0.0278 | 0.12900 | 1.73e-05 | 0.131 | 0.0896 | 92.544 | 4 | 54 |
You can also search for tracks recommendations based on another track. You can choose the number of recommended tracks returned:
recommended_songs <- get_tracks_recommendations_by_name('Arctic Monkeys', 'Do I Wanna Know?', limit = 10)
track_name | popularity | artist_name | track_duration_ms | track_mp3_30s | track_url | artist_url | artist_uri | track_uri |
---|---|---|---|---|---|---|---|---|
Let It Happen | 76 | Tame Impala | 467586 | NULL | 5INjqkS1o8h1imAzPqGZBb | 2X485T9Z5Ly0xyaghN73ed | ||
Somebody Told Me | 70 | The Killers | 197160 | NULL | 0C0XlULifJtAgn6ZNCW2eu | 59XNy4523UcEvQfYM8fdQB | ||
Clint Eastwood | 69 | Gorillaz | 340920 | 3AA28KZvwAUcZuOKwyblJQ | 7yMiX7n9SBvadzox8T5jzT | |||
I Want It All | 62 | Arctic Monkeys | 185406 | 7Ln80lUS6He07XvHI8qqHH | 1j9rezdE3YeC7yktZXC1em | |||
24/7 | 59 | The Neighbourhood | 219973 | 77SW9BnxLY8rJ0RciFqkHh | 4Cdb1dE3pfiWlqnAIcImyQ |
Search Spotify Item
You can also search an spotify item (artist, album or track) by name with the function get_spotify_item. We can use it in four different ways:
- Search an artist (this is basically the same output as get_artist function).
search_artist <- get_spotify_item(name = 'Arctic Monkeys', type = 'artist')
artist_name | artist_uri | artist_img | num_followers | spotify_url | popularity | musical_genre |
---|---|---|---|---|---|---|
Arctic Monkeys | 7Ln80lUS6He07XvHI8qqHH | https://i.scdn.co/image/ed0552e9746ed2bbf04ae4bcb5525700ca31522d | 8780891 | 86 | garage_rock-modern_rock-permanent_wave-rock-sheffield_indie |
- Search an album with the ‘name’ parameter. In this case, we can get similar results but not exactly the album name specified in the parameter function (We can try to use a higher limit to get the desired album).
search_album <- get_spotify_item(name = 'Nuclear', type = 'album')
album_uri | album_name | album_type | album_img | album_url | release_date | release_date_precision | total_tracks | available_markets | popularity |
---|---|---|---|---|---|---|---|---|---|
3tgTuhdTPvaka7LUU4gzdb | Bang! Pow! Boom! Nuclear | album | https://i.scdn.co/image/ab67616d0000b273b6e01aed96a03d8706c91931 | 2010-04-01 | day | 23 | AD | 49 |
search_album_with_limit <- get_spotify_item(name = 'Nuclear', type = 'album', limit = 5)
album_uri | album_name | album_type | album_img | album_url | release_date | release_date_precision | total_tracks | available_markets | popularity |
---|---|---|---|---|---|---|---|---|---|
3tgTuhdTPvaka7LUU4gzdb | Bang! Pow! Boom! Nuclear | album | https://i.scdn.co/image/ab67616d0000b273b6e01aed96a03d8706c91931 | 2010-04-01 | day | 23 | AD | 49 | |
0am24qfT1RsxWY2bxhcrJB | Not Animal | album | https://i.scdn.co/image/ab67616d0000b2733365b7ae7c208abc36ede955 | 2008-10-07 | day | 12 | AD | 49 | |
2azrcCM9HIS232wphRkTTG | Nuclear Bonds | single | https://i.scdn.co/image/ab67616d0000b273d0a1f24ca9fb845889433591 | 2015-10-13 | day | 9 | AD | 41 | |
1T2uKSyUf7DBWOABtsmYLM | Nuclear | album | https://i.scdn.co/image/ab67616d0000b27313c4ca893a92d3a81e0cb3e8 | 2019-03-22 | day | 12 | AD | 71 | |
3MDHsd4SZfMtCdM8Clihqp | THE DUST OF RETREAT (EXPLICIT) | album | https://i.scdn.co/image/ab67616d0000b273c455808106bb65b0cff01bde | 2005 | year | 12 | US | 39 |
- Search an album with the ‘artist’ and ‘album’ parameters to avoid the problem.
search_album_2 <- get_spotify_item(artist = 'Leiva', album = 'Nuclear', type = 'album')
album_uri | album_name | album_type | album_img | album_url | release_date | release_date_precision | total_tracks | available_markets | popularity |
---|---|---|---|---|---|---|---|---|---|
1T2uKSyUf7DBWOABtsmYLM | Nuclear | album | https://i.scdn.co/image/ab67616d0000b27313c4ca893a92d3a81e0cb3e8 | 2019-03-22 | day | 12 | AD | 71 |
- Search a specific track.
search_track <- get_spotify_item(name = 'Do I Wanna Know?' , type = 'track')
track_name | track_uri | artist_name | artist_uri | disc_number | track_duration_ms | explicit | spotify_url | track_mp3_30s | track_number |
---|---|---|---|---|---|---|---|---|---|
Do I Wanna Know? | 5FVd6KXrgO9B3JPmC8OPst | Arctic Monkeys | 7Ln80lUS6He07XvHI8qqHH | 1 | 272394 | FALSE | 1 |
Issues
If you find some type of error, bug or doubt, please, let me know it here .
DSpoty Shiny App
The DSpoty App is an R Shiny Dashboard that shows multiple information based on DSpoty R package. You can access this App from here .
License
This package (DSpoty) is licensed under the MIT License.
A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.