2022-01-16 00:29:50 +00:00
|
|
|
use std::{env, process::exit};
|
2019-08-05 21:42:16 +00:00
|
|
|
|
2022-01-16 00:29:50 +00:00
|
|
|
use librespot::{
|
|
|
|
core::{
|
|
|
|
authentication::Credentials, config::SessionConfig, session::Session, spotify_id::SpotifyId,
|
|
|
|
},
|
|
|
|
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();
|
2024-09-13 05:35:55 +00:00
|
|
|
if args.len() != 3 {
|
|
|
|
eprintln!("Usage: {} ACCESS_TOKEN PLAYLIST", args[0]);
|
2021-03-06 00:29:08 +00:00
|
|
|
return;
|
2019-08-05 21:42:16 +00:00
|
|
|
}
|
2024-09-13 05:35:55 +00:00
|
|
|
let credentials = Credentials::with_access_token(&args[1]);
|
2019-08-05 21:42:16 +00:00
|
|
|
|
2024-09-13 05:35:55 +00:00
|
|
|
let plist_uri = SpotifyId::from_uri(&args[2]).unwrap_or_else(|_| {
|
2022-02-14 11:15:19 +00:00
|
|
|
eprintln!(
|
|
|
|
"PLAYLIST should be a playlist URI such as: \
|
|
|
|
\"spotify:playlist:37i9dQZF1DXec50AjHrNTq\""
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
});
|
2020-01-17 17:11:07 +00:00
|
|
|
|
2022-01-16 00:29:50 +00:00
|
|
|
let session = Session::new(session_config, None);
|
2022-07-27 21:31:11 +00:00
|
|
|
if let Err(e) = session.connect(credentials, false).await {
|
2022-01-16 00:29:50 +00:00
|
|
|
println!("Error connecting: {}", e);
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-08-05 21:42:16 +00:00
|
|
|
|
2022-08-03 20:50:21 +00:00
|
|
|
let plist = Playlist::get(&session, &plist_uri).await.unwrap();
|
2020-01-17 17:11:07 +00:00
|
|
|
println!("{:?}", plist);
|
2021-12-07 22:52:34 +00:00
|
|
|
for track_id in plist.tracks() {
|
2022-08-03 20:50:21 +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);
|
|
|
|
}
|
|
|
|
}
|