listenbrainz-rs/examples/submit_listens.rs

94 lines
2.5 KiB
Rust
Raw Permalink Normal View History

2021-01-14 01:49:41 +00:00
use std::time::{SystemTime, UNIX_EPOCH};
2021-01-19 22:41:54 +00:00
use listenbrainz::raw::request::{ListenType, Payload, SubmitListens, TrackMetadata};
2021-01-19 22:45:43 +00:00
use listenbrainz::raw::Client;
2021-01-14 01:49:41 +00:00
fn now() -> i64 {
2021-01-14 02:29:21 +00:00
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as i64
2021-01-14 01:49:41 +00:00
}
fn main() {
let token = std::env::args().nth(1).expect("No token provided");
let client = Client::new();
2021-01-14 01:49:41 +00:00
// 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 {
2021-01-14 02:29:21 +00:00
listened_at: Some(now() - 60 * 5),
2021-01-14 01:49:41 +00:00
track_metadata: TrackMetadata {
artist_name: "Lil Tecca",
track_name: "All Star (with Lil Tjay)",
release_name: None,
additional_info: None,
},
};
let second = Payload {
2021-01-14 02:29:21 +00:00
listened_at: Some(now() - 60 * 15),
2021-01-14 01:49:41 +00:00
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 {
2021-01-14 02:29:21 +00:00
listened_at: Some(now() - 60 * 10),
2021-01-14 01:49:41 +00:00
track_metadata: TrackMetadata {
artist_name: "Alkaline Trio",
track_name: "Fall Victim",
release_name: Some("Crimson"),
additional_info: None,
2021-01-14 02:29:21 +00:00
},
2021-01-14 01:49:41 +00:00
};
let submission = SubmitListens {
listen_type: ListenType::Import,
payload: &[first, second, third],
};
let result = client.submit_listens(&token, submission);
println!("{:#?}", result);
}