2022-01-16 00:29:50 +00:00
|
|
|
use std::{env, process::exit};
|
|
|
|
|
|
|
|
use librespot::{
|
|
|
|
core::{
|
2022-11-22 12:17:29 +00:00
|
|
|
authentication::Credentials,
|
|
|
|
config::SessionConfig,
|
|
|
|
session::Session,
|
|
|
|
spotify_id::{SpotifyId, SpotifyItemType},
|
2022-01-16 00:29:50 +00:00
|
|
|
},
|
|
|
|
playback::{
|
|
|
|
audio_backend,
|
|
|
|
config::{AudioFormat, PlayerConfig},
|
2022-07-27 21:31:11 +00:00
|
|
|
mixer::NoOpVolume,
|
2022-01-16 00:29:50 +00:00
|
|
|
player::Player,
|
|
|
|
},
|
|
|
|
};
|
2017-04-28 22:24:55 +00:00
|
|
|
|
2021-03-06 00:29:08 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2017-08-03 19:11:30 +00:00
|
|
|
let session_config = SessionConfig::default();
|
|
|
|
let player_config = PlayerConfig::default();
|
2021-03-12 22:18:18 +00:00
|
|
|
let audio_format = AudioFormat::default();
|
2017-04-28 22:24:55 +00:00
|
|
|
|
2018-02-26 01:50:41 +00:00
|
|
|
let args: Vec<_> = env::args().collect();
|
2024-09-13 05:35:55 +00:00
|
|
|
if args.len() != 3 {
|
|
|
|
eprintln!("Usage: {} ACCESS_TOKEN TRACK", args[0]);
|
2021-03-06 00:29:08 +00:00
|
|
|
return;
|
2017-04-28 22:24:55 +00:00
|
|
|
}
|
2024-09-13 05:35:55 +00:00
|
|
|
let credentials = Credentials::with_access_token(&args[1]);
|
2017-04-28 22:24:55 +00:00
|
|
|
|
2024-09-13 05:35:55 +00:00
|
|
|
let mut track = SpotifyId::from_base62(&args[2]).unwrap();
|
2022-11-04 00:10:49 +00:00
|
|
|
track.item_type = SpotifyItemType::Track;
|
2017-04-28 22:24:55 +00:00
|
|
|
|
|
|
|
let backend = audio_backend::find(None).unwrap();
|
|
|
|
|
2022-01-16 00:29:50 +00:00
|
|
|
println!("Connecting...");
|
|
|
|
let session = Session::new(session_config, None);
|
2022-07-27 21:31:11 +00:00
|
|
|
if let Err(e) = session.connect(credentials, false).await {
|
2022-01-16 00:29:50 +00:00
|
|
|
println!("Error connecting: {}", e);
|
|
|
|
exit(1);
|
|
|
|
}
|
2017-04-28 22:24:55 +00:00
|
|
|
|
2023-06-13 14:56:40 +00:00
|
|
|
let player = Player::new(player_config, session, Box::new(NoOpVolume), move || {
|
2021-04-10 08:27:24 +00:00
|
|
|
backend(None, audio_format)
|
2019-10-08 09:31:18 +00:00
|
|
|
});
|
2017-04-28 22:24:55 +00:00
|
|
|
|
2020-02-02 00:07:05 +00:00
|
|
|
player.load(track, true, 0);
|
|
|
|
|
2017-04-28 22:24:55 +00:00
|
|
|
println!("Playing...");
|
2021-03-06 00:29:08 +00:00
|
|
|
|
|
|
|
player.await_end_of_track().await;
|
2017-04-28 22:24:55 +00:00
|
|
|
|
|
|
|
println!("Done");
|
|
|
|
}
|