aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Cargo.lock62
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs62
-rw-r--r--templates/home.html.tera4
4 files changed, 126 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 74e154b..c2e24d8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,12 @@
version = 3
[[package]]
+name = "adler"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
+
+[[package]]
name = "aead"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -97,6 +103,21 @@ dependencies = [
]
[[package]]
+name = "attohttpc"
+version = "0.24.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b85f766c20e6ae766956f7a2fcc4e0931e79a7e1f48b29132b5d647021114914"
+dependencies = [
+ "flate2",
+ "http",
+ "log",
+ "native-tls",
+ "serde",
+ "serde_json",
+ "url",
+]
+
+[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -284,6 +305,15 @@ dependencies = [
]
[[package]]
+name = "crc32fast"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
+dependencies = [
+ "cfg-if 1.0.0",
+]
+
+[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -448,6 +478,16 @@ dependencies = [
]
[[package]]
+name = "flate2"
+version = "1.0.25"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
+dependencies = [
+ "crc32fast",
+ "miniz_oxide",
+]
+
+[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -963,6 +1003,17 @@ dependencies = [
]
[[package]]
+name = "listenbrainz"
+version = "0.5.0"
+source = "git+https://sectorinf.com/cel/listenbrainz-rs.git#b0cd2d6b8aa3d56fa3308a741cadc365d3683b6c"
+dependencies = [
+ "attohttpc",
+ "serde",
+ "serde_json",
+ "thiserror",
+]
+
+[[package]]
name = "lock_api"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1018,6 +1069,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
+name = "miniz_oxide"
+version = "0.6.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"
+dependencies = [
+ "adler",
+]
+
+[[package]]
name = "mio"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1840,9 +1900,11 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
name = "site"
version = "0.1.0"
dependencies = [
+ "listenbrainz",
"reqwest",
"rocket",
"rocket_dyn_templates",
+ "serde",
"tokio",
]
diff --git a/Cargo.toml b/Cargo.toml
index c584041..c05bd31 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,4 +9,6 @@ edition = "2021"
rocket = { version = "0.5.0-rc.2", features = ["json"] }
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
+serde = { version = "1.0", features = ["derive"] }
rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["tera"] }
+listenbrainz = { git = "https://sectorinf.com/cel/listenbrainz-rs.git" }
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")]
diff --git a/templates/home.html.tera b/templates/home.html.tera
index 7ffd4aa..3396894 100644
--- a/templates/home.html.tera
+++ b/templates/home.html.tera
@@ -20,8 +20,8 @@
</iframe>
{% endif %}
-{% if is_scrobbling %}
-<a href="https://listenbrainz.org/user/celblossom" class="panel" id="scrobble">now playing: Parfum d'étoiles - Ichiko Aoba</a>
+{% if listenbrainz.is_scrobbling %}
+<a href="https://listenbrainz.org/user/celblossom" class="panel" id="scrobble">now playing: {{ listenbrainz.song }} - {{ listenbrainz.artist }}</a>
{% endif %}
{% endblock header %}