README.md

DSpoty

Lifecycle:
stable Build Status

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 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 22469906 93 glam\_rock-rock The Beatles 3WrFJ7ztbogyGnTHbHJFl2 14688077 91 british\_invasion-merseybeat-psychedelic\_rock-rock Twenty One Pilots 3YQKmKGau1PzlVlkL1iodx 15682408 88 modern\_rock-rock Maroon 5 04gDigrS5kc9YWfZHwBETP 21450933 94 pop-pop\_rock Imagine Dragons 53XhwfbYqKCa1cC15pYq2q 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 Alex Turner 1ctkBmvz80MGyi72Ix055S 66 The Last Shadow Puppets 2Z7UcsdweVlRbAk5wH5fsf 65 Blossoms 22RISwgVJyZu9lpqAcv1F5 66 Kasabian 11wRdbnoYqRddKBrpHt4Ue 69

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):

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 2012-01-01 day 36 CA 14 1GvWtv7m3NX1vZ1Lk4i13M The BRIT Awards 2012 appears\_on compilation 2012-01-01 day 61 GB 29 5GaeDKlnZggETclP0Y3FfE Domino Sampler ’11 appears\_on compilation 2011-12-20 day 18 CA 9 4jqIQ4srPIBcTcPdGFxdGF All The Rage appears\_on compilation 2008-02-01 day 15 AD 29 3Vx8n3WCI0s0l2mvS0IMg3 Again & Again appears\_on single 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_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 8780891 86 garage\_rock-modern\_rock-permanent\_wave-rock-sheffield\_indie
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 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 2010-04-01 day 23 AD 49 0am24qfT1RsxWY2bxhcrJB Not Animal album 2008-10-07 day 12 AD 49 2azrcCM9HIS232wphRkTTG Nuclear Bonds single 2015-10-13 day 9 AD 41 1T2uKSyUf7DBWOABtsmYLM Nuclear album 2019-03-22 day 12 AD 71 3MDHsd4SZfMtCdM8Clihqp THE DUST OF RETREAT (EXPLICIT) album 2005 year 12 US 39
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 2019-03-22 day 12 AD 71
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.



Try the DSpoty package in your browser

Any scripts or data that you put into this service are public.

DSpoty documentation built on March 26, 2020, 7:13 p.m.