From ce2b34851d38dc28d6ffbbb4fe563e226acb7445 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 16 Jan 2026 17:14:48 +0100 Subject: finish refactoring import crate --- import/src/plugins/misc.rs | 72 +++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) (limited to 'import/src/plugins/misc.rs') diff --git a/import/src/plugins/misc.rs b/import/src/plugins/misc.rs index 97bb6a5..ff08d87 100644 --- a/import/src/plugins/misc.rs +++ b/import/src/plugins/misc.rs @@ -11,12 +11,7 @@ use jellydb::table::RowNum; use jellyremuxer::matroska::{AttachedFile, Segment}; use log::info; use regex::Regex; -use std::{ - fs::{File, read_to_string}, - io::Read, - path::Path, - sync::LazyLock, -}; +use std::{fs::File, io::Read, path::Path, sync::LazyLock}; pub struct ImageFiles; impl ImportPlugin for ImageFiles { @@ -52,7 +47,7 @@ impl ImportPlugin for ImageFiles { node = node .as_object() .update(NO_PICTURES, |picts| picts.insert(slot, &asset)); - ct.dba.nodes.update(txn, row, node); + ct.dba.nodes.update(txn, row, node)?; Ok(()) })?; Ok(()) @@ -102,12 +97,12 @@ impl ImportPlugin for General { fn instruction(&self, ct: &ImportContext, node: RowNum, line: &str) -> Result<()> { if line == "hidden" { ct.dba.update_node(node, |node| { - node.visibility = node.visibility.min(Visibility::Hidden); + node.as_object().insert(NO_VISIBILITY, VISI_HIDDEN) })?; } if line == "reduced" { - ct.db.update_node_init(node, |node| { - node.visibility = node.visibility.min(Visibility::Reduced); + ct.dba.update_node(node, |node| { + node.as_object().insert(NO_VISIBILITY, VISI_REDUCED) })?; } if let Some(kind) = line.strip_prefix("kind-").or(line.strip_prefix("kind=")) { @@ -124,20 +119,17 @@ impl ImportPlugin for General { "episode" => KIND_EPISODE, _ => bail!("unknown node kind"), }; - ct.db.update_node_init(node, |node| { - node.kind = kind; - })?; + ct.dba + .update_node(node, |node| node.as_object().insert(NO_KIND, kind))?; } if let Some(title) = line.strip_prefix("title=") { - ct.db.update_node_init(node, |node| { - node.title = Some(title.to_owned()); - })?; + ct.dba + .update_node(node, |node| node.as_object().insert(NO_TITLE, title))?; } if let Some(index) = line.strip_prefix("index=") { let index = index.parse().context("parse index")?; - ct.db.update_node_init(node, |node| { - node.index = Some(index); - })?; + ct.dba + .update_node(node, |node| node.as_object().insert(NO_INDEX, index))?; } Ok(()) } @@ -153,20 +145,21 @@ impl ImportPlugin for Children { } } fn file(&self, ct: &ImportContext, parent: RowNum, path: &Path) -> Result<()> { - let filename = path.file_name().unwrap().to_string_lossy(); - if filename.as_ref() == "children" { - info!("import children at {path:?}"); - for line in read_to_string(path)?.lines() { - let line = line.trim(); - if line.starts_with("#") || line.is_empty() { - continue; - } - ct.db.update_node_init(NodeID::from_slug(line), |n| { - n.slug = line.to_owned(); - n.parents.insert(parent); - })?; - } - } + // TODO use idents + // let filename = path.file_name().unwrap().to_string_lossy(); + // if filename.as_ref() == "children" { + // info!("import children at {path:?}"); + // for line in read_to_string(path)?.lines() { + // let line = line.trim(); + // if line.starts_with("#") || line.is_empty() { + // continue; + // } + // ct.db.update_node_init(NodeID::from_slug(line), |n| { + // n.slug = line.to_owned(); + // n.parents.insert(parent); + // })?; + // } + // } Ok(()) } } @@ -188,16 +181,17 @@ impl ImportPlugin for EpisodeIndex { if let Some(cap) = RE_EPISODE_FILENAME.captures(&filename) { if let Some(episode) = cap.name("episode").map(|m| m.as_str()) { let season = cap.name("season").map(|m| m.as_str()); - let episode = episode.parse::().context("parse episode num")?; + let episode = episode.parse::().context("parse episode num")?; let season = season .unwrap_or("1") - .parse::() + .parse::() .context("parse season num")?; - ct.db.update_node_init(node, |node| { - node.kind = NodeKind::Episode; - node.index = Some(episode); - node.season_index = Some(season); + ct.dba.update_node(node, |mut node| { + node = node.as_object().insert(NO_SEASON_INDEX, season); + node = node.as_object().insert(NO_INDEX, episode); + node = node.as_object().insert(NO_KIND, KIND_EPISODE); + node })?; } } -- cgit v1.3