play.rs 1.3 KB

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