2017-04-28 22:24:55 +00:00
|
|
|
use std::env;
|
|
|
|
|
2019-10-07 21:19:45 +00:00
|
|
|
use librespot::core::authentication::Credentials;
|
|
|
|
use librespot::core::config::SessionConfig;
|
|
|
|
use librespot::core::session::Session;
|
|
|
|
use librespot::core::spotify_id::SpotifyId;
|
2018-02-22 12:24:04 +00:00
|
|
|
use librespot::playback::audio_backend;
|
2021-04-10 08:27:24 +00:00
|
|
|
use librespot::playback::config::{AudioFormat, PlayerConfig};
|
2022-05-19 20:23:14 +00:00
|
|
|
use librespot::playback::mixer::NoOpVolume;
|
2020-02-02 00:07:05 +00:00
|
|
|
use librespot::playback::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();
|
2017-04-28 22:24:55 +00:00
|
|
|
if args.len() != 4 {
|
2021-03-06 00:29:08 +00:00
|
|
|
eprintln!("Usage: {} USERNAME PASSWORD TRACK", args[0]);
|
|
|
|
return;
|
2017-04-28 22:24:55 +00:00
|
|
|
}
|
2021-03-06 00:29:08 +00:00
|
|
|
let credentials = Credentials::with_password(&args[1], &args[2]);
|
2017-04-28 22:24:55 +00:00
|
|
|
|
2018-02-25 02:04:07 +00:00
|
|
|
let track = SpotifyId::from_base62(&args[3]).unwrap();
|
2017-04-28 22:24:55 +00:00
|
|
|
|
|
|
|
let backend = audio_backend::find(None).unwrap();
|
|
|
|
|
|
|
|
println!("Connecting ..");
|
2021-04-01 16:10:42 +00:00
|
|
|
let session = Session::connect(session_config, credentials, None)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2017-04-28 22:24:55 +00:00
|
|
|
|
2022-05-19 20:23:14 +00:00
|
|
|
let (mut 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");
|
|
|
|
}
|