librespot/examples/playlist_tracks.rs

56 lines
1.7 KiB
Rust
Raw Normal View History

2019-08-05 21:42:16 +00:00
extern crate log;
extern crate env_logger;
extern crate librespot;
extern crate tokio_core;
2019-08-05 21:42:16 +00:00
//extern crate tokio_fs;
2019-08-05 21:42:16 +00:00
extern crate tokio_io;
extern crate futures;
2019-08-05 21:42:16 +00:00
//extern crate futures_cpupool;
2019-08-05 21:42:16 +00:00
use std::env;
use tokio_core::reactor::Core;
use librespot::core::authentication::Credentials;
use librespot::core::config::SessionConfig;
use librespot::core::session::Session;
use librespot::core::spotify_id::SpotifyId;
2019-08-05 21:42:16 +00:00
use librespot::playback::config::PlayerConfig;
use librespot::playback::config::Bitrate;
2019-08-06 20:02:25 +00:00
use librespot::metadata::{Metadata, Track, Playlist};
2019-08-05 21:42:16 +00:00
fn main() {
env_logger::init();
let mut core = Core::new().unwrap();
let handle = core.handle();
let session_config = SessionConfig::default();
2019-08-05 21:42:16 +00:00
let mut player_config = PlayerConfig::default();
player_config.bitrate = Bitrate::Bitrate320;
2019-08-05 21:42:16 +00:00
let args: Vec<_> = env::args().collect();
2019-08-06 19:58:50 +00:00
if args.len() != 4 {
println!("Usage: {} USERNAME PASSWORD PLAYLIST", args[0]);
2019-08-05 21:42:16 +00:00
}
let username = args[1].to_owned();
let password = args[2].to_owned();
let credentials = Credentials::with_password(username, password);
2019-08-06 20:02:25 +00:00
let uri_split = args[3].split(":");
2019-08-05 21:42:16 +00:00
let uri_parts: Vec<&str> = uri_split.collect();
println!("{}, {}, {}",uri_parts[0], uri_parts[1], uri_parts[2]);
let plist_uri = SpotifyId::from_base62(uri_parts[2]).unwrap();
let session = core
.run(Session::connect(session_config, credentials, None, handle))
.unwrap();
2019-08-06 19:58:50 +00:00
let plist = core.run(Playlist::get(&session, plist_uri)).unwrap();
2019-08-05 21:42:16 +00:00
println!("{:?}",plist);
for track_id in plist.tracks {
let plist_track = core.run(Track::get(&session, track_id)).unwrap();
println!("track: {} ", plist_track.name);
}
}