From 0a2f1d909aed3c807a30589aeca17f81c694dd37 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 4 Aug 2023 22:07:14 +0200 Subject: show view count and likes --- server/src/routes/ui/node.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'server/src') diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index 2c335d3..83719d0 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -17,7 +17,7 @@ use crate::{ uri, }; use anyhow::{anyhow, Context}; -use jellycommon::{MediaInfo, NodeKind, NodePublic, SourceTrackKind}; +use jellycommon::{MediaInfo, NodeKind, NodePublic, Rating, SourceTrackKind}; use rocket::{get, serde::json::Json, Either, State}; #[get("/n/")] @@ -74,7 +74,7 @@ markup::define! { } NodeCard<'a>(id: &'a str, node: &'a NodePublic) { @PosterCard { - wide: matches!(node.kind, NodeKind::Collection), + wide: matches!(node.kind, NodeKind::Collection | NodeKind::Video), dir: !matches!(node.kind, NodeKind::Movie | NodeKind::Episode), id, title: &node.title @@ -129,6 +129,13 @@ markup::define! { p { @format_duration(m.duration) } p { @m.resolution_name() } } + @for r in &node.ratings { + p { @match r { + Rating::YoutubeLikes(n) => { @format_count(*n) " Likes" } + Rating::YoutubeViews(n) => { @format_count(*n) " Views" } + _ => { "Unknown Rating" } + } } + } } h3 { @node.tagline } p { @node.description } @@ -187,6 +194,7 @@ impl MediaInfoExt for MediaInfo { match maxw { 7680.. => "8K", 3840.. => "4K", + 2560.. => "WQHD", 1920.. => "Full HD", 1280.. => "HD 720p", 640.. => "NTSC", @@ -194,3 +202,15 @@ impl MediaInfoExt for MediaInfo { } } } + +fn format_count(n: impl Into) -> String { + let n: usize = n.into(); + + if n >= 1_000_000 { + format!("{:.1}M", n as f32 / 1_000_000.) + } else if n >= 1_000 { + format!("{:.1}k", n as f32 / 1_000.) + } else { + format!("{n}") + } +} -- cgit v1.2.3-70-g09d2