2020-08-25 21:13:46 +00:00
|
|
|
use std::env;
|
|
|
|
|
2022-01-16 00:29:50 +00:00
|
|
|
use librespot::core::{authentication::Credentials, config::SessionConfig, session::Session};
|
2020-08-25 21:13:46 +00:00
|
|
|
|
|
|
|
const SCOPES: &str =
|
|
|
|
"streaming,user-read-playback-state,user-modify-playback-state,user-read-currently-playing";
|
|
|
|
|
2021-03-06 00:29:08 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2024-09-13 05:35:55 +00:00
|
|
|
let mut builder = env_logger::Builder::new();
|
|
|
|
builder.parse_filters("librespot=trace");
|
|
|
|
builder.init();
|
|
|
|
|
|
|
|
let mut session_config = SessionConfig::default();
|
2020-08-25 21:13:46 +00:00
|
|
|
|
|
|
|
let args: Vec<_> = env::args().collect();
|
2024-09-13 05:35:55 +00:00
|
|
|
if args.len() == 3 {
|
|
|
|
// Only special client IDs have sufficient privileges e.g. Spotify's.
|
|
|
|
session_config.client_id = args[2].clone()
|
|
|
|
} else if args.len() != 2 {
|
|
|
|
eprintln!("Usage: {} ACCESS_TOKEN [CLIENT_ID]", args[0]);
|
2021-03-06 00:29:08 +00:00
|
|
|
return;
|
2020-08-25 21:13:46 +00:00
|
|
|
}
|
2024-09-13 05:35:55 +00:00
|
|
|
let access_token = &args[1];
|
2020-08-25 21:13:46 +00:00
|
|
|
|
2024-09-13 05:35:55 +00:00
|
|
|
// Now create a new session with that token.
|
|
|
|
let session = Session::new(session_config.clone(), None);
|
|
|
|
let credentials = Credentials::with_access_token(access_token);
|
|
|
|
println!("Connecting with token..");
|
2022-07-27 21:31:11 +00:00
|
|
|
match session.connect(credentials, false).await {
|
2024-09-13 05:35:55 +00:00
|
|
|
Ok(()) => println!("Session username: {:#?}", session.username()),
|
|
|
|
Err(e) => {
|
|
|
|
println!("Error connecting: {e}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let token = session.token_provider().get_token(SCOPES).await.unwrap();
|
|
|
|
println!("Got me a token: {token:#?}");
|
2020-08-25 21:13:46 +00:00
|
|
|
}
|