diff options
author | metamuffin <metamuffin@disroot.org> | 2023-06-14 20:38:19 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-06-14 20:38:19 +0200 |
commit | 7cc616e965b4a4eb5a8c759c7230f9d8d01821c0 (patch) | |
tree | a6f13f69c6e3035bdbcc2bb87f6de66cb98d7911 | |
parent | 90fb37475efa3269bfc7313457e25489193c882c (diff) | |
download | jellything-7cc616e965b4a4eb5a8c759c7230f9d8d01821c0.tar jellything-7cc616e965b4a4eb5a8c759c7230f9d8d01821c0.tar.bz2 jellything-7cc616e965b4a4eb5a8c759c7230f9d8d01821c0.tar.zst |
generalize share props between item and dir
-rw-r--r-- | common/src/lib.rs | 36 | ||||
-rw-r--r-- | remuxer/src/lib.rs | 2 | ||||
-rw-r--r-- | server/src/library.rs | 14 | ||||
-rw-r--r-- | server/src/routes/ui/node.rs | 12 |
4 files changed, 38 insertions, 26 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs index 47015ff..c678cdb 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -3,13 +3,21 @@ pub mod r#impl; use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize}; -use std::{collections::BTreeMap, path::PathBuf}; +use std::{collections::BTreeMap, path::PathBuf, ops::Deref}; #[derive(Debug, Clone, Deserialize, Serialize)] -pub struct DirectoryInfo { - pub name: String, - pub banner: Option<PathBuf>, +pub struct CommmonInfo { + pub title: String, + #[serde(default)] pub tagline: Option<String>, + #[serde(default)] pub description: Option<String>, + #[serde(default)] pub poster: Option<PathBuf>, + #[serde(default)] pub backdrop: Option<PathBuf>, +} +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct DirectoryInfo { + #[serde(flatten)] + pub commmon: CommmonInfo, #[serde(default)] pub kind: DirectoryKind, } @@ -30,12 +38,9 @@ impl Default for DirectoryKind { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct ItemInfo { - pub title: String, + #[serde(flatten)] + pub commmon: CommmonInfo, pub duration: f64, // in seconds - pub description_head: String, - pub description: String, - pub poster: Option<PathBuf>, - pub backdrop: Option<PathBuf>, pub tracks: BTreeMap<usize, SourceTrack>, } @@ -78,3 +83,16 @@ pub struct BlockIndex { pub source_off: usize, pub size: usize, } + +impl Deref for ItemInfo { + type Target = CommmonInfo; + fn deref(&self) -> &Self::Target { + &self.commmon + } +} +impl Deref for DirectoryInfo { + type Target = CommmonInfo; + fn deref(&self) -> &Self::Target { + &self.commmon + } +}
\ No newline at end of file diff --git a/remuxer/src/lib.rs b/remuxer/src/lib.rs index 5352b14..e531f06 100644 --- a/remuxer/src/lib.rs +++ b/remuxer/src/lib.rs @@ -116,7 +116,7 @@ impl RemuxerContext { output.write_tag(&MatroskaTag::Info(Master::Collected(vec![ MatroskaTag::TimestampScale(1_000_000), MatroskaTag::Duration(iteminfo.duration * 1000.0), - MatroskaTag::Title(iteminfo.title), + MatroskaTag::Title(iteminfo.title.clone()), MatroskaTag::MuxingApp("jellyremux".to_string()), MatroskaTag::WritingApp("jellything".to_string()), ])))?; diff --git a/server/src/library.rs b/server/src/library.rs index 517f50a..30d6e69 100644 --- a/server/src/library.rs +++ b/server/src/library.rs @@ -4,7 +4,7 @@ Copyright (C) 2023 metamuffin <metamuffin.org> */ use anyhow::{anyhow, bail, Context, Ok}; -use jellycommon::{DirectoryInfo, ItemInfo}; +use jellycommon::{DirectoryInfo, ItemInfo, CommmonInfo}; use log::info; use std::{ ffi::OsStr, @@ -83,10 +83,10 @@ impl Node { Node::Directory(_) => bail!("not an item"), } } - pub fn title(&self) -> &str { + pub fn commmon(&self) -> &CommmonInfo { match self { - Node::Directory(d) => &d.info.name, - Node::Item(i) => &i.info.title, + Node::Directory(d) => &d.info.commmon, + Node::Item(i) => &i.info.commmon, } } pub fn identifier(&self) -> &str { @@ -95,12 +95,6 @@ impl Node { Node::Item(i) => &i.identifier, } } - pub fn poster(&self) -> &Option<PathBuf> { - match self { - Node::Directory(d) => &d.info.banner, - Node::Item(i) => &i.info.poster, - } - } pub fn from_path( path: PathBuf, diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index a4ef6f3..d5e52ff 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -31,7 +31,7 @@ pub async fn r_library_node( .nested_path(&path) .context("retrieving library node")?; Ok(LayoutPage { - title: node.title().to_string(), + title: node.commmon().title.to_string(), show_back: node.get_item().is_ok(), content: markup::new! { @NodePage { node: &node } @@ -63,14 +63,14 @@ markup::define! { } p.title { a[href=uri!(r_library_node(&dir.lib_path))] { - @dir.info.name + @dir.info.title } } } } DirectoryPage<'a>(dir: &'a Arc<Directory>) { div.page.dir { - h1 { @dir.info.name } + h1 { @dir.info.title } @if let Some(parent) = dir.lib_path.parent() { a.dirup[href=uri!(r_library_node(&parent))] { "Go up" } } @@ -109,7 +109,7 @@ markup::define! { a.play[href=&player_uri(&item.lib_path)] { "Watch now" } } div.details { - h3 { @item.info.description_head } + h3 { @item.info.tagline } p { @item.info.description } } } @@ -138,8 +138,8 @@ pub async fn r_item_assets( .info .backdrop .clone() - .or_else(|| node.poster().clone()), - AssetRole::Poster => node.poster().clone(), + .or_else(|| node.commmon().poster.clone()), + AssetRole::Poster => node.commmon().poster.clone(), }; let path = if let Some(p) = path { library.root_path.join(p) |