diff options
author | metamuffin <metamuffin@disroot.org> | 2023-12-22 10:09:22 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-12-22 10:09:22 +0100 |
commit | 6056fa9df419c1745b0c4f246e95c0b73fbcb645 (patch) | |
tree | 7e08ba07ce9d00b5eae1e14857cc9b62967529f2 | |
parent | b92983fb0cab2a284301b930d2b15ec0109dd93e (diff) | |
download | jellything-6056fa9df419c1745b0c4f246e95c0b73fbcb645.tar jellything-6056fa9df419c1745b0c4f246e95c0b73fbcb645.tar.bz2 jellything-6056fa9df419c1745b0c4f246e95c0b73fbcb645.tar.zst |
rework import pt. 3: auto children
-rw-r--r-- | common/src/lib.rs | 13 | ||||
-rw-r--r-- | import/src/lib.rs | 40 |
2 files changed, 41 insertions, 12 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs index 9a3535a..ce83bd4 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -21,8 +21,10 @@ use std::{collections::BTreeMap, path::PathBuf}; #[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct Node { - #[serde(default)] pub public: NodePublic, - #[serde(default)] pub private: NodePrivate, + #[serde(default)] + pub public: NodePublic, + #[serde(default)] + pub private: NodePrivate, } #[rustfmt::skip] @@ -62,7 +64,9 @@ pub struct ImportOptions { pub enum ImportSource { Override(Node), Tmdb(u64), - AutoChildren, + AutoChildren { + path: Option<PathBuf>, + }, Media { location: AssetLocation, // TODO ignore options @@ -140,7 +144,8 @@ pub struct SourceTrack { pub codec: String, pub language: String, pub default_duration: Option<u64>, - #[serde(default)] pub federated: Vec<String>, + #[serde(default)] + pub federated: Vec<String>, } #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] diff --git a/import/src/lib.rs b/import/src/lib.rs index ed0af2d..4f83653 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -7,7 +7,7 @@ pub mod infojson; pub mod tmdb; -use anyhow::{Context, Ok}; +use anyhow::{anyhow, Context, Ok}; use async_recursion::async_recursion; use futures::{stream::FuturesUnordered, StreamExt}; use jellybase::{ @@ -201,8 +201,31 @@ async fn process_source( .await .context("federated import")? } - ImportSource::AutoChildren => { - // TODO dont forget to update path of children + ImportSource::AutoChildren { path: cpath } => { + let paths = cpath + .unwrap_or_else(|| path.parent().unwrap().to_path_buf()) + .read_dir()? + .map(Result::unwrap) + .map(|e| e.path()) + .filter(|e| e.extension() == Some(&OsStr::from_bytes(b"yaml"))); + + let mut children = Vec::new(); + for p in paths { + let opts: ImportOptions = serde_yaml::from_reader(File::open(&p)?)?; + if opts.id != id { + children.push(opts.id); + } + } + insert_node( + &id, + Node { + private: NodePrivate::default(), + public: NodePublic { + children, + ..Default::default() + }, + }, + )?; } } Ok(()) @@ -215,11 +238,12 @@ fn merge_node(x: Node, y: Node) -> Node { title: x.public.title.or(y.public.title), id: x.public.id.or(y.public.id), path: vec![], - children: if x.public.children.is_empty() { - x.public.children - } else { - y.public.children - }, + children: x + .public + .children + .into_iter() + .chain(y.public.children) + .collect(), tagline: x.public.tagline.or(y.public.tagline), description: x.public.description.or(y.public.description), release_date: x.public.release_date.or(y.public.release_date), |