diff options
Diffstat (limited to 'server/src/routes')
-rw-r--r-- | server/src/routes/ui/assets.rs | 1 | ||||
-rw-r--r-- | server/src/routes/ui/home.rs | 10 | ||||
-rw-r--r-- | server/src/routes/ui/node.rs | 47 | ||||
-rw-r--r-- | server/src/routes/ui/player.rs | 10 |
4 files changed, 47 insertions, 21 deletions
diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs index 7df7cf0..ddbc2ee 100644 --- a/server/src/routes/ui/assets.rs +++ b/server/src/routes/ui/assets.rs @@ -51,6 +51,7 @@ pub async fn r_item_assets( Ok(asset_with_res(asset, width).await?) } +// TODO this can create "federation recursion" because track selection cannot be relied on. #[get("/n/<id>/thumbnail?<t>&<width>")] pub async fn r_node_thumbnail( session: Session, diff --git a/server/src/routes/ui/home.rs b/server/src/routes/ui/home.rs index 6a3b9a4..d332447 100644 --- a/server/src/routes/ui/home.rs +++ b/server/src/routes/ui/home.rs @@ -84,27 +84,27 @@ pub fn r_home(sess: Session, db: &State<Database>) -> MyResult<DynLayoutPage> { title: "Home".to_string(), content: markup::new! { h2 { "Explore " @CONF.brand } - .homelist { ul {@for (id, node, udata) in &toplevel { + .hlist { ul {@for (id, node, udata) in &toplevel { li { @NodeCard { id, node, udata } } }}} @if !continue_watching.is_empty() { h2 { "Continue Watching" } - .homelist { ul {@for (id, node, udata) in &continue_watching { + .hlist { ul {@for (id, node, udata) in &continue_watching { li { @NodeCard { id, node, udata } } }}} } @if !watchlist.is_empty() { h2 { "Watchlist" } - .homelist { ul {@for (id, node, udata) in &watchlist { + .hlist { ul {@for (id, node, udata) in &watchlist { li { @NodeCard { id, node, udata } } }}} } h2 { "Latest Releases" } - .homelist { ul {@for (id, node, udata) in &latest { + .hlist { ul {@for (id, node, udata) in &latest { li { @NodeCard { id, node, udata } } }}} h2 { "Today's Picks" } - .homelist { ul {@for (id, node, udata) in &random { + .hlist { ul {@for (id, node, udata) in &random { li { @NodeCard { id, node, udata } } }}} p.error { "TODO: recently added" } diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index adbe5b1..0dbb027 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -4,7 +4,7 @@ Copyright (C) 2023 metamuffin <metamuffin.org> */ use super::{ - assets::rocket_uri_macro_r_item_assets, + assets::{rocket_uri_macro_r_item_assets, rocket_uri_macro_r_node_thumbnail}, error::MyError, sort::{filter_and_sort_nodes, NodeFilterSort, NodeFilterSortForm}, }; @@ -12,13 +12,13 @@ use crate::{ database::Database, routes::{ api::AcceptJson, - userdata::{rocket_uri_macro_r_player_watched, UrlWatchedState}, ui::{ account::session::Session, assets::AssetRole, layout::{DynLayoutPage, LayoutPage}, player::{rocket_uri_macro_r_player, PlayerConfig}, }, + userdata::{rocket_uri_macro_r_player_watched, UrlWatchedState}, }, uri, }; @@ -143,20 +143,27 @@ markup::define! { p { @for line in description.lines() { @line br; } } } @if let Some(media) = &node.media { + @if !media.chapters.is_empty() { + h2 { "Chapters" } + .hlist { ul.children { @for chap in &media.chapters { + @let (inl, sub) = format_chapter(chap); + li { .card."aspect-thumb" { + .poster { + a[href=&uri!(r_player(id, PlayerConfig::seek(chap.time_start.unwrap_or(0.))))] { + img[src=&uri!(r_node_thumbnail(id, chapter_key_time(chap, media.duration), Some(1024)))]; + } + .cardhover { .props { p { @inl } } } + } + .title { @sub } + }} + }}} + } details { summary { "Tracks" } ol { @for track in &media.tracks { li { @format!("{track}") } }} } - @if !media.chapters.is_empty() { - details { - summary { "Chapters" } - ol { @for chap in &media.chapters { - li { @format_chapter(chap) } - }} - } - } } } @if matches!(node.kind.unwrap_or_default(), NodeKind::Collection | NodeKind::Channel) { @@ -297,11 +304,19 @@ fn format_count(n: impl Into<usize>) -> String { } } -fn format_chapter(c: &Chapter) -> String { - format!( - "{}-{}: {}", - c.time_start.map(format_duration).unwrap_or_default(), - c.time_end.map(format_duration).unwrap_or_default(), - c.labels.first().map(|l| l.1.clone()).unwrap_or_default() +fn format_chapter(c: &Chapter) -> (String, String) { + ( + format!( + "{}-{}", + c.time_start.map(format_duration).unwrap_or_default(), + c.time_end.map(format_duration).unwrap_or_default(), + ), + c.labels.first().map(|l| l.1.clone()).unwrap_or_default(), ) } + +fn chapter_key_time(c: &Chapter, dur: f64) -> f64 { + let start = c.time_start.unwrap_or(0.); + let end = c.time_end.unwrap_or(dur); + start * 0.8 + end * 0.2 +} diff --git a/server/src/routes/ui/player.rs b/server/src/routes/ui/player.rs index 8b8adf6..e3c5cb2 100644 --- a/server/src/routes/ui/player.rs +++ b/server/src/routes/ui/player.rs @@ -29,6 +29,16 @@ pub struct PlayerConfig { pub a: Option<TrackID>, pub v: Option<TrackID>, pub s: Option<TrackID>, + pub t: Option<f64>, +} + +impl PlayerConfig { + pub fn seek(t: f64) -> Self { + Self { + t: Some(t), + ..Default::default() + } + } } #[get("/n/<id>/player?<conf..>", rank = 4)] |