play.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. extern crate librespot;
  2. extern crate tokio_core;
  3. use std::env;
  4. use tokio_core::reactor::Core;
  5. use librespot::core::authentication::Credentials;
  6. use librespot::core::config::{PlayerConfig, SessionConfig};
  7. use librespot::core::session::Session;
  8. use librespot::core::util::SpotifyId;
  9. use librespot::audio_backend;
  10. use librespot::player::Player;
  11. fn main() {
  12. let mut core = Core::new().unwrap();
  13. let handle = core.handle();
  14. let session_config = SessionConfig::default();
  15. let player_config = PlayerConfig::default();
  16. let args : Vec<_> = env::args().collect();
  17. if args.len() != 4 {
  18. println!("Usage: {} USERNAME PASSWORD TRACK", args[0]);
  19. }
  20. let username = args[1].to_owned();
  21. let password = args[2].to_owned();
  22. let credentials = Credentials::with_password(username, password);
  23. let track = SpotifyId::from_base62(&args[3]);
  24. let backend = audio_backend::find(None).unwrap();
  25. println!("Connecting ..");
  26. let session = core.run(Session::connect(session_config, credentials, None, handle)).unwrap();
  27. let player = Player::new(player_config, session.clone(), None, move || (backend)(None));
  28. println!("Playing...");
  29. core.run(player.load(track, true, 0)).unwrap();
  30. println!("Done");
  31. }