From 3a29113e965a94bdef06655f1583cc6e86edd606 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 21 Dec 2023 23:57:42 +0100 Subject: rework import system pt. 1 --- server/src/routes/ui/admin/mod.rs | 5 ++--- server/src/routes/ui/node.rs | 22 ++++++++++++---------- server/src/routes/ui/player.rs | 2 +- server/src/routes/ui/sort.rs | 16 ++++++++-------- 4 files changed, 23 insertions(+), 22 deletions(-) (limited to 'server/src/routes/ui') diff --git a/server/src/routes/ui/admin/mod.rs b/server/src/routes/ui/admin/mod.rs index 0d1ee0a..b976192 100644 --- a/server/src/routes/ui/admin/mod.rs +++ b/server/src/routes/ui/admin/mod.rs @@ -9,8 +9,6 @@ pub mod user; use super::account::session::AdminSession; use crate::{ database::Database, - federation::Federation, - import::import, routes::ui::{ admin::log::rocket_uri_macro_r_admin_log, error::MyResult, @@ -19,7 +17,8 @@ use crate::{ uri, }; use anyhow::anyhow; -use jellybase::CONF; +use jellybase::{federation::Federation, CONF}; +use jellyimport::import; use rand::Rng; use rocket::{form::Form, get, post, FromForm, State}; use std::time::Instant; diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index 6e2f532..bcb7362 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -72,7 +72,7 @@ pub async fn r_library_node_filter<'a>( filter_and_sort_nodes(&filter, &mut children); Ok(Either::Left(LayoutPage { - title: node.title.to_string(), + title: node.title.clone().unwrap_or_default(), content: markup::new! { @NodePage { node: &node, id: &id, udata: &udata, children: &children, filter: &filter } }, @@ -82,14 +82,14 @@ pub async fn r_library_node_filter<'a>( markup::define! { NodeCard<'a>(id: &'a str, node: &'a NodePublic, udata: &'a NodeUserData) { - @let cls = format!("node card poster {}", match node.kind {NodeKind::Channel => "aspect-square", NodeKind::Video => "aspect-thumb", NodeKind::Collection => "aspect-land", _ => "aspect-port"}); + @let cls = format!("node card poster {}", match node.kind.unwrap_or_default() {NodeKind::Channel => "aspect-square", NodeKind::Video => "aspect-thumb", NodeKind::Collection => "aspect-land", _ => "aspect-port"}); div[class=cls] { .poster { a[href=uri!(r_library_node(id))] { img[src=uri!(r_item_assets(id, AssetRole::Poster, Some(1024)))]; } .cardhover.item { - @if !(matches!(node.kind, NodeKind::Collection | NodeKind::Channel)) { + @if !(matches!(node.kind.unwrap_or_default(), NodeKind::Collection | NodeKind::Channel)) { a.play.icon[href=&uri!(r_player(id, PlayerConfig::default()))] { "play_arrow" } } @Props { node, udata } @@ -103,17 +103,17 @@ markup::define! { } } NodePage<'a>(id: &'a str, node: &'a NodePublic, udata: &'a NodeUserData, children: &'a Vec<(String, NodePublic, NodeUserData)>, filter: &'a NodeFilterSort) { - @if !matches!(node.kind, NodeKind::Collection) { + @if !matches!(node.kind.unwrap_or_default(), NodeKind::Collection) { img.backdrop[src=uri!(r_item_assets(id, AssetRole::Backdrop, Some(2048)))]; } .page.node { - @if !matches!(node.kind, NodeKind::Collection) { + @if !matches!(node.kind.unwrap_or_default(), NodeKind::Collection) { div.bigposter { img[src=uri!(r_item_assets(id, AssetRole::Poster, Some(2048)))]; } } .title { h1 { @node.title } @if node.media.is_some() { a.play[href=&uri!(r_player(id, PlayerConfig::default()))] { "Watch now" }} - @if !matches!(node.kind, NodeKind::Collection | NodeKind::Channel) { + @if !matches!(node.kind.unwrap_or_default(), NodeKind::Collection | NodeKind::Channel) { @match udata.watched { WatchedState::None | WatchedState::Progress(_) => { @@ -152,15 +152,15 @@ markup::define! { } } } - @if matches!(node.kind, NodeKind::Collection | NodeKind::Channel) { - @if matches!(node.kind, NodeKind::Collection) { + @if matches!(node.kind.unwrap_or_default(), NodeKind::Collection | NodeKind::Channel) { + @if matches!(node.kind.unwrap_or_default(), NodeKind::Collection) { @if let Some(parent) = &node.path.last().cloned() { a.dirup[href=uri!(r_library_node(parent))] { "Go up" } } } @NodeFilterSortForm { f: filter } } - @match node.kind { + @match node.kind.unwrap_or_default() { NodeKind::Collection | NodeKind::Channel => { ul.children {@for (id, node, udata) in children.iter() { li { @NodeCard { id, node, udata } } @@ -261,7 +261,9 @@ impl MediaInfoExt for MediaInfo { let mut maxdim = 0; for t in &self.tracks { match &t.kind { - SourceTrackKind::Video { width, height, .. } => maxdim = maxdim.max(*width.max(height)), + SourceTrackKind::Video { width, height, .. } => { + maxdim = maxdim.max(*width.max(height)) + } _ => (), } } diff --git a/server/src/routes/ui/player.rs b/server/src/routes/ui/player.rs index 177a5f6..8b8adf6 100644 --- a/server/src/routes/ui/player.rs +++ b/server/src/routes/ui/player.rs @@ -59,7 +59,7 @@ pub fn r_player<'a>( let conf = player_conf(item.clone(), playing)?; Ok(LayoutPage { - title: item.public.title.to_owned(), + title: item.public.title.to_owned().unwrap_or_default(), class: Some("player"), content: markup::new! { @if playing { diff --git a/server/src/routes/ui/sort.rs b/server/src/routes/ui/sort.rs index c7fbfc2..143a101 100644 --- a/server/src/routes/ui/sort.rs +++ b/server/src/routes/ui/sort.rs @@ -139,14 +139,14 @@ pub fn filter_and_sort_nodes( o &= !match p { FilterProperty::FederationLocal => node.federated.is_none(), FilterProperty::FederationRemote => node.federated.is_some(), - FilterProperty::KindMovie => node.kind == NodeKind::Movie, - FilterProperty::KindVideo => node.kind == NodeKind::Video, - FilterProperty::KindCollection => node.kind == NodeKind::Collection, - FilterProperty::KindChannel => node.kind == NodeKind::Channel, - FilterProperty::KindShow => node.kind == NodeKind::Show, - FilterProperty::KindSeries => node.kind == NodeKind::Series, - FilterProperty::KindSeason => node.kind == NodeKind::Season, - FilterProperty::KindEpisode => node.kind == NodeKind::Episode, + FilterProperty::KindMovie => node.kind == Some(NodeKind::Movie), + FilterProperty::KindVideo => node.kind == Some(NodeKind::Video), + FilterProperty::KindCollection => node.kind == Some(NodeKind::Collection), + FilterProperty::KindChannel => node.kind == Some(NodeKind::Channel), + FilterProperty::KindShow => node.kind == Some(NodeKind::Show), + FilterProperty::KindSeries => node.kind == Some(NodeKind::Series), + FilterProperty::KindSeason => node.kind == Some(NodeKind::Season), + FilterProperty::KindEpisode => node.kind == Some(NodeKind::Episode), FilterProperty::Watched => udata.watched == WatchedState::Watched, FilterProperty::Unwatched => udata.watched == WatchedState::None, FilterProperty::WatchProgress => { -- cgit v1.2.3-70-g09d2 From 826c61c9612e855b19c3adb0e93d80bbfb4dc903 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 22 Dec 2023 00:29:11 +0100 Subject: rework import system pt. 2 --- Cargo.lock | 2 ++ common/src/lib.rs | 4 +-- import/Cargo.toml | 4 +-- import/src/lib.rs | 65 ++++++++++++++++++++++++++++++++++++++++++-- server/src/routes/ui/home.rs | 2 +- tool/src/main.rs | 13 --------- 6 files changed, 69 insertions(+), 21 deletions(-) (limited to 'server/src/routes/ui') diff --git a/Cargo.lock b/Cargo.lock index 9a12441..bd09a54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1391,9 +1391,11 @@ dependencies = [ "jellybase", "jellyclient", "jellycommon", + "jellymatroska", "jellyremuxer", "log", "reqwest", + "serde", "serde_json", "serde_yaml", "tokio", diff --git a/common/src/lib.rs b/common/src/lib.rs index e953d85..9a3535a 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -21,8 +21,8 @@ use std::{collections::BTreeMap, path::PathBuf}; #[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct Node { - pub public: NodePublic, - pub private: NodePrivate, + #[serde(default)] pub public: NodePublic, + #[serde(default)] pub private: NodePrivate, } #[rustfmt::skip] diff --git a/import/Cargo.toml b/import/Cargo.toml index f2ba7af..a54967c 100644 --- a/import/Cargo.toml +++ b/import/Cargo.toml @@ -7,14 +7,14 @@ edition = "2021" jellycommon = { path = "../common" } jellybase = { path = "../base" } jellyclient = { path = "../client" } -# jellymatroska = { path = "../matroska" } +jellymatroska = { path = "../matroska" } jellyremuxer = { path = "../remuxer" } log = { workspace = true } anyhow = "1.0.75" reqwest = { version = "0.11.22", features = ["blocking", "json"] } -# serde = { version = "1.0.193", features = ["derive"] } +serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.108" serde_yaml = "0.9.27" # bincode = { version = "2.0.0-rc.3", features = ["serde"] } diff --git a/import/src/lib.rs b/import/src/lib.rs index 3698f79..ed0af2d 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -4,6 +4,9 @@ Copyright (C) 2023 metamuffin */ #![feature(lazy_cell)] +pub mod infojson; +pub mod tmdb; + use anyhow::{Context, Ok}; use async_recursion::async_recursion; use futures::{stream::FuturesUnordered, StreamExt}; @@ -14,16 +17,19 @@ use jellyclient::Session; use jellycommon::{ AssetLocation, AssetRole, ImportOptions, ImportSource, Node, NodePrivate, NodePublic, }; +use jellymatroska::read::EbmlReader; +use jellyremuxer::import::import_metadata; use log::{debug, info}; use std::{ cmp::Ordering, ffi::OsStr, fs::File, + io::BufReader, os::unix::prelude::OsStrExt, path::{Path, PathBuf}, sync::{Arc, LazyLock}, }; -use tokio::sync::Semaphore; +use tokio::{sync::Semaphore, task::spawn_blocking}; static IMPORT_SEM: LazyLock = LazyLock::new(|| Semaphore::new(1)); @@ -48,12 +54,15 @@ pub fn merge_nodes(db: &Database) -> anyhow::Result<()> { nodes.sort_by(|(x, _), (y, _)| compare_index_path(x, y)); - let node = nodes + let mut node = nodes .into_iter() .map(|(_, x)| x) .reduce(|x, y| merge_node(x, y)) .unwrap(); + node.public.id = Some(id.clone()); + node.public.path = vec!["library".to_string()]; // TODO reconstruct from children + db.node.insert(&id, &node)?; } Ok(()) @@ -146,7 +155,44 @@ async fn process_source( ImportSource::Override(n) => insert_node(&id, n)?, ImportSource::Tmdb(_) => todo!(), ImportSource::Media { location } => { - let path = location.path(); + let media_path = location.path(); + + let metadata = spawn_blocking(move || { + let input = BufReader::new(File::open(&media_path).unwrap()); + let mut input = EbmlReader::new(input); + import_metadata(&mut input) + }) + .await??; + + // if let Some(cover) = metadata.cover { + // let pu = path.join(format!( + // "cover.{}", + // match mime.as_str() { + // "image/webp" => "webp", + // "image/jpeg" => "jpeg", + // "image/png" => "png", + // _ => { + // warn!("unknown mime, just using webp"); + // "webp" + // } + // } + // )); + // if !pu.exists() { + // let mut f = tokio::fs::File::create(&pu).await?; + // f.write_all(&data).await?; + // } + // } + + let node = Node { + public: NodePublic { + title: metadata.title, + description: metadata.description, + tagline: metadata.tagline, + ..Default::default() + }, + private: NodePrivate::default(), + }; + insert_node(&id, node)?; } ImportSource::Federated { host } => { let session = fed.get_session(&host).await.context("creating session")?; @@ -374,3 +420,16 @@ async fn cache_federation_asset( ) .await } + +fn make_ident(s: &str) -> String { + let mut out = String::new(); + for s in s.chars() { + match s { + 'a'..='z' | '0'..='9' => out.push(s), + 'A'..='Z' => out.push(s.to_ascii_lowercase()), + '-' | ' ' | '_' | ':' => out.push('-'), + _ => (), + } + } + out +} diff --git a/server/src/routes/ui/home.rs b/server/src/routes/ui/home.rs index bcbc847..74e9b02 100644 --- a/server/src/routes/ui/home.rs +++ b/server/src/routes/ui/home.rs @@ -77,7 +77,7 @@ pub fn r_home(sess: Session, db: &State) -> MyResult { Ok(LayoutPage { title: "Home".to_string(), content: markup::new! { - p { "Welcome back " @sess.user.display_name } + p { "Welcome back, " @sess.user.display_name } h2 { "Explore " @CONF.brand } .homelist { ul {@for (id, node, udata) in &toplevel { li { @NodeCard { id, node, udata } } diff --git a/tool/src/main.rs b/tool/src/main.rs index 34337ce..6384822 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -193,19 +193,6 @@ fn main() -> anyhow::Result<()> { } } -fn make_ident(s: &str) -> String { - let mut out = String::new(); - for s in s.chars() { - match s { - 'a'..='z' | '0'..='9' => out.push(s), - 'A'..='Z' => out.push(s.to_ascii_lowercase()), - '-' | ' ' | '_' | ':' => out.push('-'), - _ => (), - } - } - out -} - fn ok_or_warn(r: Result) -> Option { match r { Ok(t) => Some(t), -- cgit v1.2.3-70-g09d2