Skip to contents
library(SpotifyAssistantR)
#> Loading required package: spotifyr
#> Loading required package: dplyr
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#> Loading required package: rlang

SpotifyAssistantR

This package uses wrapper functions from the Spotify API and SpotifyR and combines them to give Spotify users more insight about their listening habits. It has four main functions: 1. Getting the most recent song releases by continent 2. Getting the user’s top genres 3. Getting the user’s playlists and tracks 4. Getting new song recommendations based on the user’s top artists

Initial Setup

In order to use the SpotifyAssistantR package, the user must have a Spotify account, as well as a Spotify Developer Account. Click here to create a Spotify Developer account.

Client ID and Secret

Once the developer account has been made, log in and go to the user Dashboard. Click on the green CREATE AN APP button and name the new app. Once the app has been created, the user will be immediately redirected to the app overview page. On this page, directly under the name of the app, there are some pieces of information. Note down the Client ID. This is one of the two credentials necessary for using the functions in this package. The Client ID should be set as a System Environment variable, as in the following:

Sys.setenv(SPOTIFY_CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxx')

Click on SHOW CLIENT SECRET. Note down Client Secret. This is the other credential necessary for using the functions in this package. It should also be set as a System Environment variable, as in the following:

Sys.setenv(SPOTIFY_CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxx')

Please note that these two credentials should be confidential, and they are unique to the app.

Redirect URI

In the app overview page, aside from the Client ID and Secret information, there is one more part to the setup process. Click on the green EDIT SETTINGS button on the right side of the page. Add the following as a Redirect URI:

http://localhost:1410/

Now the setup process is complete.

Getting New Releases by Continent

The following function will return one album from the Americas (i.e. North and South America).

get_new_releases_by_continent(continent = 'Americas', limit = 1)
# -- Loading new releases in  Americas , this may take a while... 
# [1] "Wet Leg"

Other continents that can be specified are: ‘Asia’, ‘Europe’, ‘Oceania’, and ‘Africa’. The number of albums to be returned can also be increased by increasing the limit.

Getting User Top Genres

The following function will return the user’s top genres based on their listening trends and among the tracks in “Your Music” library.

get_users_top_genres()
# [1] "rap"     "pop"     "hip hop" "pop rap" "trap"

Getting User Playlists and Tracks

The following function will return the all user’s saved playlists and tracks:

Playlists can also be specified using the playlist_names argument, like this:

# for one playlist
get_playlists_songs(playlist_names = 'bops')

# [1] "Getting songs for bops"
# $bops
#   [1] "hot girl bummer"                                          
#   [2] "Salt"                                                     
#   [3] "Don't Start Now"  

# for more than one playlist
get_playlists_songs(playlist_names = c('bops', 'night drives'))

# [1] "Getting songs for night drives"
# [1] "Getting songs for bops"
# $`night drives`
#  [1] "Sunset (2019 Y.Nakamura Remastering)"               
#  [2] "Plastic Love"
# $bops
#   [1] "hot girl bummer"                                          
#   [2] "Salt"                                                     
#   [3] "Don't Start Now"

Getting User Song Recommendations

The following function will create a new playlist on Spotify, containing recommended songs for the user based on the user’s top artists. It is possible to specify a name for the new playlist using the playlist_name argument. If this is left blank, the playlist will simply be named “Recommended Songs” followed by the current date. The user can also specify the number of songs to return in the playlist using the num_songs argument. The default is 10 songs.

get_song_recommendations()
# [1] "Generating recommended songs based on artists ..."
# [1] "Here is a link to the new playlist: https://open.spotify.com/playlist/2CB2JEtHcraGS0GeEkzEUW"