aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.rs62
1 files changed, 60 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 65a40c4..7e61f15 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,13 +1,71 @@
+use listenbrainz::raw::response::UserPlayingNowResponse;
use rocket::fs::{relative, FileServer};
-use rocket::{response::Responder, serde::json::Json};
+use rocket::response::Responder;
use rocket_dyn_templates::{context, Template};
+use serde::{Deserialize, Serialize};
#[macro_use]
extern crate rocket;
+#[derive(Serialize, Deserialize)]
+struct ScrobbleData {
+ is_scrobbling: bool,
+ song: Option<String>,
+ artist: Option<String>,
+}
+
+impl ScrobbleData {
+ fn new(playingnow: UserPlayingNowResponse) -> Self {
+ let is_scrobbling = playingnow.payload.count > 0;
+ if is_scrobbling {
+ Self {
+ is_scrobbling,
+ song: Some(
+ playingnow
+ .payload
+ .listens
+ .first()
+ .unwrap()
+ .track_metadata
+ .track_name
+ .clone(),
+ ),
+ artist: Some(
+ playingnow
+ .payload
+ .listens
+ .first()
+ .unwrap()
+ .track_metadata
+ .artist_name
+ .clone(),
+ ),
+ }
+ } else {
+ Self {
+ is_scrobbling,
+ song: None,
+ artist: None,
+ }
+ }
+ }
+}
+
#[get("/")]
async fn home() -> Template {
- Template::render("home", context! { is_live: true, is_scrobbling: true })
+ let listenbrainz = listenbrainz::raw::Client::new();
+ let playingnow = listenbrainz.user_playing_now("celblossom").unwrap();
+ println!(
+ "{}",
+ playingnow.payload.listens[0].track_metadata.artist_name
+ );
+ let listenbrainz_data = ScrobbleData::new(playingnow);
+ println!("{}", listenbrainz_data.is_scrobbling);
+
+ Template::render(
+ "home",
+ context! { is_live: false, listenbrainz: listenbrainz_data },
+ )
}
#[get("/contact")]