Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Get Track Features From The Spotify API In Rust

rust
//! ```cargo
//! [dependencies]
//! rspotify = { version = "0.12.0", default-features = false, features = ["client-ureq", "ureq-rustls-tls", "env-file"] }
//! ```

#![allow(non_snake_case)]
use rspotify::{model::TrackId, prelude::*, ClientCredsSpotify, Credentials};

fn main() {
    let chunk_size = 2; // up to 50
    let ids = vec![
      "spotify:track:0UlwTmT01jdFp3BaofARtU",
      "spotify:track:7MXK7DwU1DpGFTA31AZW6S",
      "spotify:track:0Lz0VvjdDvO8LaUOPW94iT",
      "spotify:track:3obwANwnr6iXVABsOnXLNC",
      "spotify:track:5xYZXIgVAND5sWjN8G0hID",
    ];
    let creds = Credentials::from_env().unwrap();
    let spotify = ClientCredsSpotify::new(creds);
    spotify.request_token().unwrap();
    let track_ids = ids.iter().map(|id| TrackId::from_uri(id).unwrap()).collect::<Vec<TrackId>>();
     track_ids.chunks(chunk_size).for_each(|track_set| {
        let tracks = spotify.tracks_features(track_set.to_owned());
        dbg!(tracks.ok());
    });
}
results start

- You can get up to 50 tracks at a time

- This one is done syncronously since I'm working with an SQLite database for inserts and don't want to hit it async

- The credentails come from a .env file with : [TODO: Code shorthand span ] , [TODO: Code shorthand span ] for Spotify Client Credentails auth

Footnotes And References