diff --git a/examples/get_token.rs b/examples/get_token.rs index 3ef6bd71..a568ae07 100644 --- a/examples/get_token.rs +++ b/examples/get_token.rs @@ -1,8 +1,6 @@ use std::env; -use librespot::core::authentication::Credentials; -use librespot::core::config::SessionConfig; -use librespot::core::session::Session; +use librespot::core::{authentication::Credentials, config::SessionConfig, session::Session}; const SCOPES: &str = "streaming,user-read-playback-state,user-modify-playback-state,user-read-currently-playing"; @@ -17,14 +15,15 @@ async fn main() { return; } - println!("Connecting.."); + println!("Connecting..."); let credentials = Credentials::with_password(&args[1], &args[2]); - let session = Session::connect(session_config, credentials, None) - .await - .unwrap(); + let session = Session::new(session_config, None); - println!( - "Token: {:#?}", - session.token_provider().get_token(SCOPES).await.unwrap() - ); + match session.connect(credentials).await { + Ok(()) => println!( + "Token: {:#?}", + session.token_provider().get_token(SCOPES).await.unwrap() + ), + Err(e) => println!("Error connecting: {}", e), + } } diff --git a/examples/play.rs b/examples/play.rs index d6c7196d..3cbbc43b 100644 --- a/examples/play.rs +++ b/examples/play.rs @@ -1,12 +1,15 @@ -use std::env; +use std::{env, process::exit}; -use librespot::core::authentication::Credentials; -use librespot::core::config::SessionConfig; -use librespot::core::session::Session; -use librespot::core::spotify_id::SpotifyId; -use librespot::playback::audio_backend; -use librespot::playback::config::{AudioFormat, PlayerConfig}; -use librespot::playback::player::Player; +use librespot::{ + core::{ + authentication::Credentials, config::SessionConfig, session::Session, spotify_id::SpotifyId, + }, + playback::{ + audio_backend, + config::{AudioFormat, PlayerConfig}, + player::Player, + }, +}; #[tokio::main] async fn main() { @@ -25,10 +28,12 @@ async fn main() { let backend = audio_backend::find(None).unwrap(); - println!("Connecting .."); - let session = Session::connect(session_config, credentials, None) - .await - .unwrap(); + println!("Connecting..."); + let session = Session::new(session_config, None); + if let Err(e) = session.connect(credentials).await { + println!("Error connecting: {}", e); + exit(1); + } let (mut player, _) = Player::new(player_config, session, None, move || { backend(None, audio_format) diff --git a/examples/playlist_tracks.rs b/examples/playlist_tracks.rs index 0b19e73e..2f53a8a3 100644 --- a/examples/playlist_tracks.rs +++ b/examples/playlist_tracks.rs @@ -1,10 +1,11 @@ -use std::env; +use std::{env, process::exit}; -use librespot::core::authentication::Credentials; -use librespot::core::config::SessionConfig; -use librespot::core::session::Session; -use librespot::core::spotify_id::SpotifyId; -use librespot::metadata::{Metadata, Playlist, Track}; +use librespot::{ + core::{ + authentication::Credentials, config::SessionConfig, session::Session, spotify_id::SpotifyId, + }, + metadata::{Metadata, Playlist, Track}, +}; #[tokio::main] async fn main() { @@ -24,9 +25,11 @@ async fn main() { let plist_uri = SpotifyId::from_base62(uri_parts[2]).unwrap(); - let session = Session::connect(session_config, credentials, None) - .await - .unwrap(); + let session = Session::new(session_config, None); + if let Err(e) = session.connect(credentials).await { + println!("Error connecting: {}", e); + exit(1); + } let plist = Playlist::get(&session, plist_uri).await.unwrap(); println!("{:?}", plist);