Skip to content

Instantly share code, notes, and snippets.

@JosiahParry
Created September 9, 2019 14:51
Show Gist options
  • Save JosiahParry/610427731304b00317caab25faf4d321 to your computer and use it in GitHub Desktop.
Save JosiahParry/610427731304b00317caab25faf4d321 to your computer and use it in GitHub Desktop.
track_audio_features <- possibly(.f = {
function(artist, title, type = "track") {
search_results <- search_spotify(paste(artist, title), type = type)
track_audio_feats <- get_track_audio_features(search_results$id[[1]]) %>%
dplyr::select(-id, -uri, -track_href, -analysis_url)
return(track_audio_feats)
}}, otherwise = tibble())
@drew-walkerr
Copy link

is there any way to modify this to pull for multiple tracks? Or a list of tracks?

@JosiahParry
Copy link
Author

Hey Drew, per my comment on charlie86/spotifyr#76 I'd recommend looking at the way I outline this in Ch. 3 of mirr. I would use purrr::map() to do this.

The code I used looks like this:

charts %>%
  mutate(audio_features = map2(artist, title, possible_feats)) %>%
  unnest() 

Read through chapter three and I think that'll help!

@drew-walkerr
Copy link

Hi Josiah, 
This helped tremendously! I am working on a project that analyzes spotify listening history fora study involving patient directed music with Spotify in patients/families in a pediatric intensive care unit to try to assess music analysis patterns and changes in vital signs, pain, anxiety, and biomarker symptoms of hospital-induced delirium for pediatric patients. This was a crucial point for me to figure out and I greatly appreciate your help and responsiveness. I really like your blog as well, and look forward to learning more about your work. Thanks so much for your contribution to this tool. In another section you mentioned it really opening up the API to use with other sources and it really does.
Sincerely, 
Drew

@JosiahParry
Copy link
Author

Hey @drew-walkerr, so sorry for not getting back to you on this! I hope this has gone well :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment