-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.R
44 lines (35 loc) · 1.36 KB
/
Test.R
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
# This Script Downloads the Audio Features for
# the Playlist Top Hits of 1970. The purpose is to
# view the data and see how to select the desired columns
# before making the general script that gets the playlists
# from 1970 to 2019.
# libraries
library(spotifyr)
library(dplyr)
library(readr)
# Get the Access Token
access.token <- get_spotify_access_token(
client_id = Sys.getenv("SPOTIFY_CLIENT_ID"),
client_secret = Sys.getenv("SPOTIFY_CLIENT_SECRET")
)
# Top Hits of 1970 ID: 37i9dQZF1DWXQyLTHGuTIz
# user: Spotify
hits.1970 <- get_playlist_audio_features(
"Spotify", # creator of the playlist
"37i9dQZF1DWXQyLTHGuTIz", # playlist's id
authorization = access.token
)
# write the tibble in a csv
write_csv(hits.1970, "./data/test_hits_1970.csv")
# ******** Getting the playlist's ID with a search query ********
# in order to have reproducibility, the ID must be obtained with code, in this
# case with the function search_spotify() which looks for a playlist info
p.name <- "Top Hits of 1970"
playlists.search <- search_spotify(q = p.name,
type = "playlist", authorization = access.token,
limit = 1)
# making sure the result is the playlist created by Spotify
playlist.info <- playlists.search %>%
filter(owner.display_name=="Spotify" & name == p.name)
playlist.id <- playlist.info$id
playlist.id