play.rs 1.3 KB

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