use futures::stream::TryStreamExt;
use futures_util::pin_mut;
use rspotify::{prelude::*, scopes, AuthCodeSpotify, Credentials, OAuth};
#[tokio::main]
async fn main() {
env_logger::init();
let creds = Credentials::from_env().unwrap();
let oauth = OAuth::from_env(scopes!("user-library-read")).unwrap();
let spotify = AuthCodeSpotify::new(creds, oauth);
let url = spotify.get_authorize_url(false).unwrap();
spotify.prompt_for_token(&url).await.unwrap();
let stream = spotify.current_user_saved_tracks(None);
pin_mut!(stream);
println!("Items (blocking):");
while let Some(item) = stream.try_next().await.unwrap() {
println!("* {}", item.track.name);
}
let stream = spotify.current_user_saved_tracks(None);
println!("\nItems (concurrent):");
stream
.try_for_each_concurrent(10, |item| async move {
println!("* {}", item.track.name);
Ok(())
})
.await
.unwrap();
}