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 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!(
match session.connect(credentials).await {
Ok(()) => println!(
"Token: {:#?}",
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::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)

View file

@ -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);