Add several example programs
This commit is contained in:
parent
06bd7997b6
commit
9ec6dabb48
|
@ -0,0 +1,18 @@
|
|||
use listenbrainz::Client;
|
||||
use listenbrainz::models::request::DeleteListen;
|
||||
|
||||
fn main() {
|
||||
let mut args = std::env::args().skip(1);
|
||||
let token = args.next().expect("No token provided");
|
||||
let listened_at = args.next().expect("No listened_at provided");
|
||||
let recording_msid = args.next().expect("No recording_msid provided");
|
||||
|
||||
let mut client = Client::new();
|
||||
|
||||
let delete = DeleteListen {
|
||||
listened_at: listened_at.parse().unwrap(),
|
||||
recording_msid: &recording_msid,
|
||||
};
|
||||
let result = client.delete_listen(&token, delete);
|
||||
println!("{:#?}", result);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
use listenbrainz::Client;
|
||||
|
||||
fn main() {
|
||||
let mut client = Client::new();
|
||||
|
||||
let result = client.stats_sitewide_artists(None, None, Some("year"));
|
||||
println!("{:#?}", result);
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use listenbrainz::Client;
|
||||
use listenbrainz::models::request::{SubmitListens, ListenType, Payload, TrackMetadata};
|
||||
|
||||
fn now() -> i64 {
|
||||
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() as i64
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let token = std::env::args().nth(1).expect("No token provided");
|
||||
|
||||
let mut client = Client::new();
|
||||
|
||||
// Submit single
|
||||
|
||||
let listen = Payload {
|
||||
listened_at: Some(now()),
|
||||
track_metadata: TrackMetadata {
|
||||
artist_name: "Rick Astley",
|
||||
track_name: "Never Gonna Give You Up",
|
||||
release_name: None,
|
||||
additional_info: None,
|
||||
},
|
||||
};
|
||||
let submission = SubmitListens {
|
||||
listen_type: ListenType::Single,
|
||||
payload: &[listen],
|
||||
};
|
||||
|
||||
let result = client.submit_listens(&token, submission);
|
||||
println!("{:#?}", result);
|
||||
|
||||
// Submit playing now
|
||||
|
||||
let now_playing = Payload {
|
||||
listened_at: None,
|
||||
track_metadata: TrackMetadata {
|
||||
artist_name: "Rick Astley",
|
||||
track_name: "Never Gonna Give You Up",
|
||||
release_name: None,
|
||||
additional_info: None,
|
||||
},
|
||||
};
|
||||
let submission = SubmitListens {
|
||||
listen_type: ListenType::PlayingNow,
|
||||
payload: &[now_playing],
|
||||
};
|
||||
|
||||
let result = client.submit_listens(&token, submission);
|
||||
println!("{:#?}", result);
|
||||
|
||||
// Submit imports
|
||||
|
||||
let first = Payload {
|
||||
listened_at: Some(now() - 60*5),
|
||||
track_metadata: TrackMetadata {
|
||||
artist_name: "Lil Tecca",
|
||||
track_name: "All Star (with Lil Tjay)",
|
||||
release_name: None,
|
||||
additional_info: None,
|
||||
},
|
||||
};
|
||||
let second = Payload {
|
||||
listened_at: Some(now() - 60*15),
|
||||
track_metadata: TrackMetadata {
|
||||
artist_name: "Queens of the Stone Age",
|
||||
track_name: "None One Knows",
|
||||
release_name: Some("Songs For The Deaf"),
|
||||
additional_info: None,
|
||||
},
|
||||
};
|
||||
let third = Payload {
|
||||
listened_at: Some(now() - 60*10),
|
||||
track_metadata: TrackMetadata {
|
||||
artist_name: "Alkaline Trio",
|
||||
track_name: "Fall Victim",
|
||||
release_name: Some("Crimson"),
|
||||
additional_info: None,
|
||||
}
|
||||
};
|
||||
|
||||
let submission = SubmitListens {
|
||||
listen_type: ListenType::Import,
|
||||
payload: &[first, second, third],
|
||||
};
|
||||
|
||||
let result = client.submit_listens(&token, submission);
|
||||
println!("{:#?}", result);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
use listenbrainz::Client;
|
||||
|
||||
fn main() {
|
||||
let user_name = std::env::args().nth(1).expect("No username provided");
|
||||
|
||||
let mut client = Client::new();
|
||||
|
||||
let result = client.stats_user_listening_activity(&user_name, None);
|
||||
println!("{:#?}", result);
|
||||
|
||||
let result = client.stats_user_daily_activity(&user_name, None);
|
||||
println!("{:#?}", result);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
use listenbrainz::Client;
|
||||
|
||||
fn main() {
|
||||
let user_name = std::env::args().nth(1).expect("No username provided");
|
||||
|
||||
let mut client = Client::new();
|
||||
|
||||
let result = client.stats_user_artist_map(&user_name, None, None);
|
||||
println!("{:#?}", result);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
use listenbrainz::Client;
|
||||
|
||||
fn main() {
|
||||
let user_name = std::env::args().nth(1).expect("No username provided");
|
||||
|
||||
let mut client = Client::new();
|
||||
|
||||
let result = client.user_listen_count(&user_name);
|
||||
println!("Listen count: {:#?}", result);
|
||||
|
||||
let result = client.user_playing_now(&user_name);
|
||||
println!("Playing now: {:#?}", result);
|
||||
|
||||
let result = client.user_listens(
|
||||
&user_name,
|
||||
None,
|
||||
None,
|
||||
Some(5),
|
||||
None,
|
||||
);
|
||||
println!("Recent listens: {:#?}", result);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
use listenbrainz::Client;
|
||||
|
||||
fn main() {
|
||||
let mut args = std::env::args().skip(1);
|
||||
let subject = args.next().expect("No subject provided");
|
||||
let user_name = args.next().expect("No username provided");
|
||||
|
||||
let mut client = Client::new();
|
||||
|
||||
match subject.as_str() {
|
||||
"recordings" => {
|
||||
let result = client.stats_user_recordings(&user_name, None, None, None);
|
||||
println!("{:#?}", result);
|
||||
}
|
||||
"releases" => {
|
||||
let result = client.stats_user_releases(&user_name, None, None, None);
|
||||
println!("{:#?}", result);
|
||||
}
|
||||
"artists" => {
|
||||
let result = client.stats_user_artists(&user_name, None, None, None);
|
||||
println!("{:#?}", result);
|
||||
}
|
||||
_ => {
|
||||
eprintln!(r"Subject must be one of recordings, releases, artists");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
use listenbrainz::Client;
|
||||
|
||||
fn main() {
|
||||
let token = std::env::args().nth(1).expect("No token provided");
|
||||
|
||||
let mut client = Client::new();
|
||||
|
||||
let result = client.validate_token(&token);
|
||||
println!("{:#?}", result);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
use listenbrainz::Client;
|
||||
|
||||
fn main() {
|
||||
let token = std::env::args().nth(1).unwrap();
|
||||
let mut client = Client::new();
|
||||
println!("{:#?}", client.validate_token(&token));
|
||||
}
|
Loading…
Reference in New Issue