Fix examples

This commit is contained in:
Roderick van Domburg 2022-01-16 01:29:50 +01:00
parent abbc3bade8
commit 2065ded7b6
No known key found for this signature in database
GPG key ID: FE2585E713F9F30A
3 changed files with 39 additions and 32 deletions

View file

@ -1,8 +1,6 @@
use std::env; use std::env;
use librespot::core::authentication::Credentials; use librespot::core::{authentication::Credentials, config::SessionConfig, session::Session};
use librespot::core::config::SessionConfig;
use librespot::core::session::Session;
const SCOPES: &str = const SCOPES: &str =
"streaming,user-read-playback-state,user-modify-playback-state,user-read-currently-playing"; "streaming,user-read-playback-state,user-modify-playback-state,user-read-currently-playing";
@ -17,14 +15,15 @@ async fn main() {
return; return;
} }
println!("Connecting.."); println!("Connecting...");
let credentials = Credentials::with_password(&args[1], &args[2]); let credentials = Credentials::with_password(&args[1], &args[2]);
let session = Session::connect(session_config, credentials, None) let session = Session::new(session_config, None);
.await
.unwrap();
println!( match session.connect(credentials).await {
Ok(()) => println!(
"Token: {:#?}", "Token: {:#?}",
session.token_provider().get_token(SCOPES).await.unwrap() session.token_provider().get_token(SCOPES).await.unwrap()
); ),
Err(e) => println!("Error connecting: {}", e),
}
} }

View file

@ -1,12 +1,15 @@
use std::env; use std::{env, process::exit};
use librespot::core::authentication::Credentials; use librespot::{
use librespot::core::config::SessionConfig; core::{
use librespot::core::session::Session; authentication::Credentials, config::SessionConfig, session::Session, spotify_id::SpotifyId,
use librespot::core::spotify_id::SpotifyId; },
use librespot::playback::audio_backend; playback::{
use librespot::playback::config::{AudioFormat, PlayerConfig}; audio_backend,
use librespot::playback::player::Player; config::{AudioFormat, PlayerConfig},
player::Player,
},
};
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
@ -25,10 +28,12 @@ async fn main() {
let backend = audio_backend::find(None).unwrap(); let backend = audio_backend::find(None).unwrap();
println!("Connecting .."); println!("Connecting...");
let session = Session::connect(session_config, credentials, None) let session = Session::new(session_config, None);
.await if let Err(e) = session.connect(credentials).await {
.unwrap(); println!("Error connecting: {}", e);
exit(1);
}
let (mut player, _) = Player::new(player_config, session, None, move || { let (mut player, _) = Player::new(player_config, session, None, move || {
backend(None, audio_format) backend(None, audio_format)

View file

@ -1,10 +1,11 @@
use std::env; use std::{env, process::exit};
use librespot::core::authentication::Credentials; use librespot::{
use librespot::core::config::SessionConfig; core::{
use librespot::core::session::Session; authentication::Credentials, config::SessionConfig, session::Session, spotify_id::SpotifyId,
use librespot::core::spotify_id::SpotifyId; },
use librespot::metadata::{Metadata, Playlist, Track}; metadata::{Metadata, Playlist, Track},
};
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
@ -24,9 +25,11 @@ async fn main() {
let plist_uri = SpotifyId::from_base62(uri_parts[2]).unwrap(); let plist_uri = SpotifyId::from_base62(uri_parts[2]).unwrap();
let session = Session::connect(session_config, credentials, None) let session = Session::new(session_config, None);
.await if let Err(e) = session.connect(credentials).await {
.unwrap(); println!("Error connecting: {}", e);
exit(1);
}
let plist = Playlist::get(&session, plist_uri).await.unwrap(); let plist = Playlist::get(&session, plist_uri).await.unwrap();
println!("{:?}", plist); println!("{:?}", plist);