-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
146 lines (107 loc) · 4.97 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# SpotifyAssistantR
<!-- badges: start -->
[](https://github.com/UBC-MDS/SpotifyAssistantR/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
In this project, we aim to create a package in R that builds on top of the spotifyR
package and offers more useful features to improve the Spotify user experience.
This is achieved by utilizing REST APIs to implement the functions.
Although the spotifyR package consists of wrapper functions for the Spotify REST APIs, our package will combine multiple requests from the spotifyR package to provide additional insights for Spotify users.
## Authors
- Caroline Tang
- Chester Wang
- Jenit Jain
- Julie Song
This package was originally created as part of the requirements of DSCI524 (Collaborative Software Development), a course in the Master of Data Science program at the University of British Columbia. All original members of this project abided by the [Code of Conduct](CODE_OF_CONDUCT.md).
## Installation
You can install the development version of SpotifyAssistantR like so:
``` r
devtools::install_github('UBC-MDS/SpotifyAssistantR')
```
## Dependencies
R (>=4.1.0)
- spotifyr (2.2.4)
- dplyr
## Environment Setup
Using this package requires Spotify and Spotify Developer accounts, which you can create on the
[Spotify Developer website](https://developer.spotify.com/dashboard/login). After
creating an account, you will need to create an app to obtain the necessary client ID and secret
in order to authenticate into the Spotify API.

After giving your app a name and description, you should be able to obtain the client
ID and secret from the top of the app overview:

After clicking `SHOW CLIENT SECRET`:

To use the package we require you to supplement the client ID and client secret
as environment variables:
```r
Sys.setenv(SPOTIFY_CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxx')
Sys.setenv(SPOTIFY_CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxx')
access_token <- spotifyr::get_spotify_access_token()
authentication_code <- spotifyr::get_spotify_authentication_code()
```
This must be provided after loading the `spotifyr` library and before using the package.
Running `spotifyr::get_spotify_authentication_code()` should open a new browser tab
that asks for permission for the app to access your information. If successful, you
should get a message that you can close the tab and return to R.
If this is not the case, you may need to add `http://localhost:1410/` as a
redirect URI in the app, by clicking `Edit Settings` in the app overview and
pasting the URI under `Redirect URIs`. Alternatively, you may need to rotate the
client secret and re-assign `SPOTIFY_CLIENT_SECRET`.
## Usage
These are some basic usage examples for each of the core functions:
```r
library(SpotifyAssistantR)
Sys.setenv(SPOTIFY_CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxx')
Sys.setenv(SPOTIFY_CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxx')
# Get new releases in Asia:
get_new_releases_by_continent(continent = 'Americas', n_limit=3)
# -- Loading new releases in Americas , this may take a while...
# [[1]]
# [1] "Renegade"
#
# [[2]]
# [1] "LANDER"
#
# [[3]]
# [1] "Dreaming of You"
# Get a new playlist on your Spotify account filled with recommended songs based on your top artists:
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"
# This is a simple example to get song titles from some of your saved playlists:
# 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"
# Get the top genres of music among the tracks in "Your Music" library.
get_users_top_genres()
# [1] "rap" "pop" "hip hop" "pop rap" "trap"
```
For more detailed usage information, please [see here](https://ubc-mds.github.io/SpotifyAssistantR/articles/my-vignette.html)