make listenbrainz widget
This commit is contained in:
parent
3ac85babe9
commit
859f9fe9f8
|
@ -2,6 +2,12 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "adler"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aead"
|
name = "aead"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
@ -96,6 +102,21 @@ dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[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]]
|
[[package]]
|
||||||
name = "atty"
|
name = "atty"
|
||||||
version = "0.2.14"
|
version = "0.2.14"
|
||||||
|
@ -283,6 +304,15 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[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]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
|
@ -447,6 +477,16 @@ dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flate2"
|
||||||
|
version = "1.0.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
|
||||||
|
dependencies = [
|
||||||
|
"crc32fast",
|
||||||
|
"miniz_oxide",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
|
@ -962,6 +1002,17 @@ dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "listenbrainz"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "git+https://sectorinf.com/cel/listenbrainz-rs.git#b0cd2d6b8aa3d56fa3308a741cadc365d3683b6c"
|
||||||
|
dependencies = [
|
||||||
|
"attohttpc",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.4.9"
|
version = "0.4.9"
|
||||||
|
@ -1017,6 +1068,15 @@ version = "0.3.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
|
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]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "0.6.23"
|
version = "0.6.23"
|
||||||
|
@ -1840,9 +1900,11 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
|
||||||
name = "site"
|
name = "site"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"listenbrainz",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rocket",
|
"rocket",
|
||||||
"rocket_dyn_templates",
|
"rocket_dyn_templates",
|
||||||
|
"serde",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -9,4 +9,6 @@ edition = "2021"
|
||||||
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
reqwest = { version = "0.11", features = ["json"] }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["tera"] }
|
rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["tera"] }
|
||||||
|
listenbrainz = { git = "https://sectorinf.com/cel/listenbrainz-rs.git" }
|
||||||
|
|
62
src/main.rs
62
src/main.rs
|
@ -1,13 +1,71 @@
|
||||||
|
use listenbrainz::raw::response::UserPlayingNowResponse;
|
||||||
use rocket::fs::{relative, FileServer};
|
use rocket::fs::{relative, FileServer};
|
||||||
use rocket::{response::Responder, serde::json::Json};
|
use rocket::response::Responder;
|
||||||
use rocket_dyn_templates::{context, Template};
|
use rocket_dyn_templates::{context, Template};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
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("/")]
|
#[get("/")]
|
||||||
async fn home() -> Template {
|
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")]
|
#[get("/contact")]
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
</iframe>
|
</iframe>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if is_scrobbling %}
|
{% if listenbrainz.is_scrobbling %}
|
||||||
<a href="https://listenbrainz.org/user/celblossom" class="panel" id="scrobble">now playing: Parfum d'étoiles - Ichiko Aoba</a>
|
<a href="https://listenbrainz.org/user/celblossom" class="panel" id="scrobble">now playing: {{ listenbrainz.song }} - {{ listenbrainz.artist }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endblock header %}
|
{% endblock header %}
|
||||||
|
|
Loading…
Reference in New Issue