diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-16 22:58:23 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-16 22:58:23 +0100 |
commit | 1c37d32a0985ff7390313833345b9299f9f0b196 (patch) | |
tree | cd46bcbe7df154bf506c083cf0325d44b3f4e0fb /server/src/routes/ui/node.rs | |
parent | 98b379afb31e455b529d443dcfc5797b8dd6723e (diff) | |
download | jellything-1c37d32a0985ff7390313833345b9299f9f0b196.tar jellything-1c37d32a0985ff7390313833345b9299f9f0b196.tar.bz2 jellything-1c37d32a0985ff7390313833345b9299f9f0b196.tar.zst |
chapter thumbnail display and player seek via url
Diffstat (limited to 'server/src/routes/ui/node.rs')
-rw-r--r-- | server/src/routes/ui/node.rs | 47 |
1 files changed, 31 insertions, 16 deletions
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 +} |