add is_live check
This commit is contained in:
parent
5de43f2c45
commit
27baf0ab80
|
@ -2080,9 +2080,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.93"
|
version = "1.0.97"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76"
|
checksum = "bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
@ -2158,6 +2158,7 @@ dependencies = [
|
||||||
"rocket",
|
"rocket",
|
||||||
"rocket_dyn_templates",
|
"rocket_dyn_templates",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -16,3 +16,4 @@ 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 = "0.7"
|
listenbrainz = "0.7"
|
||||||
chrono = "0.4.23"
|
chrono = "0.4.23"
|
||||||
|
serde_json = "1.0.97"
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
use reqwest::Client;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use crate::Result;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct LiveStatus {
|
||||||
|
pub online: bool,
|
||||||
|
pub viewer_count: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_live_status(client: &Client) -> Result<LiveStatus> {
|
||||||
|
let endpoint = "https://weirdstar.stream/api/status";
|
||||||
|
Ok(client
|
||||||
|
.get(endpoint)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.json::<LiveStatus>()
|
||||||
|
.await?)
|
||||||
|
}
|
15
src/main.rs
15
src/main.rs
|
@ -1,4 +1,5 @@
|
||||||
mod error;
|
mod error;
|
||||||
|
mod live;
|
||||||
mod posts;
|
mod posts;
|
||||||
mod scrobbles;
|
mod scrobbles;
|
||||||
mod skweets;
|
mod skweets;
|
||||||
|
@ -17,27 +18,30 @@ type Result<T> = std::result::Result<T, BlossomError>;
|
||||||
struct Clients {
|
struct Clients {
|
||||||
listenbrainz: listenbrainz::raw::Client,
|
listenbrainz: listenbrainz::raw::Client,
|
||||||
skinnyverse: mastodon_async::Mastodon,
|
skinnyverse: mastodon_async::Mastodon,
|
||||||
|
reqwest: reqwest::Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
async fn home(clients: &State<Clients>) -> Result<Template> {
|
async fn home(clients: &State<Clients>) -> Template {
|
||||||
let (listenbrainz, skweets) = tokio::join!(
|
let (live, listenbrainz, skweets) = tokio::join!(
|
||||||
|
live::get_live_status(&clients.reqwest),
|
||||||
scrobbles::get_now_playing(&clients.listenbrainz),
|
scrobbles::get_now_playing(&clients.listenbrainz),
|
||||||
skweets::get_recents(&clients.skinnyverse)
|
skweets::get_recents(&clients.skinnyverse)
|
||||||
);
|
);
|
||||||
|
let is_live = live.unwrap_or_default().online;
|
||||||
let listenbrainz = listenbrainz.unwrap_or_default();
|
let listenbrainz = listenbrainz.unwrap_or_default();
|
||||||
let skweets = skweets.unwrap_or_default();
|
let skweets = skweets.unwrap_or_default();
|
||||||
Ok(Template::render(
|
Template::render(
|
||||||
"home",
|
"home",
|
||||||
context! {
|
context! {
|
||||||
is_live: false,
|
is_live,
|
||||||
listenbrainz,
|
listenbrainz,
|
||||||
skweets,
|
skweets,
|
||||||
},
|
},
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/contact")]
|
#[get("/contact")]
|
||||||
|
@ -78,6 +82,7 @@ async fn main() -> std::result::Result<(), rocket::Error> {
|
||||||
.manage(Clients {
|
.manage(Clients {
|
||||||
listenbrainz: listenbrainz::raw::Client::new(),
|
listenbrainz: listenbrainz::raw::Client::new(),
|
||||||
skinnyverse: mastodon_async::Mastodon::from(skinny_data),
|
skinnyverse: mastodon_async::Mastodon::from(skinny_data),
|
||||||
|
reqwest: reqwest::Client::new(),
|
||||||
})
|
})
|
||||||
.attach(Template::custom(|engines| {
|
.attach(Template::custom(|engines| {
|
||||||
engines.tera.autoescape_on(vec![]);
|
engines.tera.autoescape_on(vec![]);
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<iframe
|
<iframe
|
||||||
class="panel"
|
class="panel"
|
||||||
id="stream"
|
id="stream"
|
||||||
src="https://live.blos.sm/embed/video"
|
src="https://weirdstar.stream/embed/video"
|
||||||
title="girlstream"
|
title="girlstream"
|
||||||
referrerpolicy="origin"
|
referrerpolicy="origin"
|
||||||
scrolling="no"
|
scrolling="no"
|
||||||
|
|
Loading…
Reference in New Issue