Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- albums <- GET(paste0('https://api.spotify.com/v1/artists/', artist_uri,'/albums')) %>% content
- library(httr)
- library(stringr)
- library(lubridate)
- #Roots uri
- artist_uri <- 78xUyw6FkVZrRAtziFdtdu
- get_albums <- function(artist_uri) {
- albums <- GET(paste0('https://api.spotify.com/v1/artists/', artist_uri,'/albums')) %>% content
- map_df(1:length(albums$items), function(x) {
- tmp <- albums$items[[x]]
- data.frame(album_uri = str_replace(tmp$uri, 'spotify:album:', ''),
- album_name = str_replace_all(tmp$name, ''', ''),
- album_img = albums$items[[x]]$images[[1]]$url,
- stringsAsFactors = F) %>%
- mutate(album_release_date = GET(paste0('https://api.spotify.com/v1/albums/', str_replace(tmp$uri, 'spotify:album:', ''))) %>% content %>% .$release_date, # you need a separate call to on "albums" to get release date.
- album_release_year = ifelse(nchar(album_release_date) == 4, year(as.Date(album_release_date, '%Y')), year(as.Date(album_release_date, '%Y-%m-%d'))) # not all album_release_dates have months, so I created album_release year for sorting
- )
- }) %>% filter(!duplicated(tolower(album_name))) %>% # Sometimes there are multiple versions (just with different capitalizations) of the same album
- arrange(album_release_year)
- }
- album_info <- get_albums(artist_info$artist_uri)
- View(album_info)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement