2019-08-05 21:42:16 +00:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
use librespot::core::authentication::Credentials;
|
|
|
|
use librespot::core::config::SessionConfig;
|
|
|
|
use librespot::core::session::Session;
|
|
|
|
use librespot::core::spotify_id::SpotifyId;
|
2020-01-17 17:11:07 +00:00
|
|
|
use librespot::metadata::{Metadata, Playlist, Track};
|
2019-08-05 21:42:16 +00:00
|
|
|
|
2021-03-06 00:29:08 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2019-08-05 21:42:16 +00:00
|
|
|
env_logger::init();
|
|
|
|
let session_config = SessionConfig::default();
|
|
|
|
|
|
|
|
let args: Vec<_> = env::args().collect();
|
2019-08-06 19:58:50 +00:00
|
|
|
if args.len() != 4 {
|
2021-03-06 00:29:08 +00:00
|
|
|
eprintln!("Usage: {} USERNAME PASSWORD PLAYLIST", args[0]);
|
|
|
|
return;
|
2019-08-05 21:42:16 +00:00
|
|
|
}
|
2021-03-06 00:29:08 +00:00
|
|
|
let credentials = Credentials::with_password(&args[1], &args[2]);
|
2019-08-05 21:42:16 +00:00
|
|
|
|
2021-03-06 00:29:08 +00:00
|
|
|
let uri_split = args[3].split(':');
|
2019-08-05 21:42:16 +00:00
|
|
|
let uri_parts: Vec<&str> = uri_split.collect();
|
2020-01-17 17:11:07 +00:00
|
|
|
println!("{}, {}, {}", uri_parts[0], uri_parts[1], uri_parts[2]);
|
|
|
|
|
2019-08-05 21:42:16 +00:00
|
|
|
let plist_uri = SpotifyId::from_base62(uri_parts[2]).unwrap();
|
2020-01-17 17:11:07 +00:00
|
|
|
|
2021-04-01 16:10:42 +00:00
|
|
|
let session = Session::connect(session_config, credentials, None)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2019-08-05 21:42:16 +00:00
|
|
|
|
2021-03-06 00:29:08 +00:00
|
|
|
let plist = Playlist::get(&session, plist_uri).await.unwrap();
|
2020-01-17 17:11:07 +00:00
|
|
|
println!("{:?}", plist);
|
2019-08-05 21:42:16 +00:00
|
|
|
for track_id in plist.tracks {
|
2021-03-06 00:29:08 +00:00
|
|
|
let plist_track = Track::get(&session, track_id).await.unwrap();
|
2019-08-05 21:42:16 +00:00
|
|
|
println!("track: {} ", plist_track.name);
|
|
|
|
}
|
|
|
|
}
|