playlist_tracks.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. use env_logger;
  2. use std::env;
  3. use tokio_core::reactor::Core;
  4. use librespot::core::authentication::Credentials;
  5. use librespot::core::config::SessionConfig;
  6. use librespot::core::session::Session;
  7. use librespot::core::spotify_id::SpotifyId;
  8. use librespot::metadata::{Metadata, Playlist, Track};
  9. fn main() {
  10. env_logger::init();
  11. let mut core = Core::new().unwrap();
  12. let handle = core.handle();
  13. let session_config = SessionConfig::default();
  14. let args: Vec<_> = env::args().collect();
  15. if args.len() != 4 {
  16. println!("Usage: {} USERNAME PASSWORD PLAYLIST", args[0]);
  17. }
  18. let username = args[1].to_owned();
  19. let password = args[2].to_owned();
  20. let credentials = Credentials::with_password(username, password);
  21. let uri_split = args[3].split(":");
  22. let uri_parts: Vec<&str> = uri_split.collect();
  23. println!("{}, {}, {}", uri_parts[0], uri_parts[1], uri_parts[2]);
  24. let plist_uri = SpotifyId::from_base62(uri_parts[2]).unwrap();
  25. let session = core
  26. .run(Session::connect(session_config, credentials, None, handle))
  27. .unwrap();
  28. let plist = core.run(Playlist::get(&session, plist_uri)).unwrap();
  29. println!("{:?}", plist);
  30. for track_id in plist.tracks {
  31. let plist_track = core.run(Track::get(&session, track_id)).unwrap();
  32. println!("track: {} ", plist_track.name);
  33. }
  34. }