diff options
Diffstat (limited to 'import/src/plugins/misc.rs')
| -rw-r--r-- | import/src/plugins/misc.rs | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/import/src/plugins/misc.rs b/import/src/plugins/misc.rs index 43bd118..97bb6a5 100644 --- a/import/src/plugins/misc.rs +++ b/import/src/plugins/misc.rs @@ -6,7 +6,7 @@ use crate::plugins::{ImportContext, ImportPlugin, PluginInfo}; use anyhow::{Context, Result, bail}; use jellycache::{HashKey, cache_store}; -use jellycommon::{PICT_BACKDROP, PICT_COVER}; +use jellycommon::{jellyobject::inspect::Inspector, *}; use jellydb::table::RowNum; use jellyremuxer::matroska::{AttachedFile, Segment}; use log::info; @@ -27,24 +27,33 @@ impl ImportPlugin for ImageFiles { ..Default::default() } } - fn file(&self, ct: &ImportContext, parent: RowNum, path: &Path) -> Result<()> { + fn file(&self, ct: &ImportContext, row: RowNum, path: &Path) -> Result<()> { let filename = path.file_name().unwrap().to_string_lossy(); let slot = match filename.as_ref() { "poster.jpeg" | "poster.webp" | "poster.png" => PICT_COVER, "backdrop.jpeg" | "backdrop.webp" | "backdrop.png" => PICT_BACKDROP, _ => return Ok(()), }; - info!("import {} at {path:?}", slot); - let asset = Asset(cache_store( - format!("media/literal/{}-{slot}.image", HashKey(path)), + info!("import {:?} at {path:?}", Inspector(&TAGREG, slot)); + let asset = cache_store( + format!( + "media/literal/{}-{}.image", + HashKey(path), + TAGREG.name(slot.0) + ), || { let mut data = Vec::new(); File::open(path)?.read_to_end(&mut data)?; Ok(data) }, - )?); - ct.db.update_node_init(parent, |node| { - node.pictures.insert(slot, asset); + )?; + ct.dba.db.write_transaction(&mut |txn| { + let mut node = ct.dba.nodes.get(txn, row)?.unwrap(); + node = node + .as_object() + .update(NO_PICTURES, |picts| picts.insert(slot, &asset)); + ct.dba.nodes.update(txn, row, node); + Ok(()) })?; Ok(()) } @@ -62,19 +71,20 @@ impl ImportPlugin for ImageAttachments { ..Default::default() } } - fn media(&self, ct: &ImportContext, node: NodeID, _path: &Path, seg: &Segment) -> Result<()> { + fn media(&self, ct: &ImportContext, row: RowNum, _path: &Path, seg: &Segment) -> Result<()> { let Some(cover) = seg .attachments .iter() .flat_map(|a| &a.files) .find(is_cover) - .map(|att| Asset(att.data.clone().try_into().unwrap())) + .map(|att| String::from_utf8_lossy(&att.data)) else { return Ok(()); }; - ct.db.update_node_init(node, |node| { - node.pictures.insert(PictureSlot::Cover, cover); + ct.dba.update_node(row, |node| { + node.as_object() + .update(NO_PICTURES, |picts| picts.insert(PICT_COVER, &cover)) })?; Ok(()) } @@ -89,9 +99,9 @@ impl ImportPlugin for General { ..Default::default() } } - fn instruction(&self, ct: &ImportContext, node: NodeID, line: &str) -> Result<()> { + fn instruction(&self, ct: &ImportContext, node: RowNum, line: &str) -> Result<()> { if line == "hidden" { - ct.db.update_node_init(node, |node| { + ct.dba.update_node(node, |node| { node.visibility = node.visibility.min(Visibility::Hidden); })?; } @@ -102,16 +112,16 @@ impl ImportPlugin for General { } if let Some(kind) = line.strip_prefix("kind-").or(line.strip_prefix("kind=")) { let kind = match kind { - "movie" => NodeKind::Movie, - "video" => NodeKind::Video, - "music" => NodeKind::Music, - "short_form_video" => NodeKind::ShortFormVideo, - "collection" => NodeKind::Collection, - "channel" => NodeKind::Channel, - "show" => NodeKind::Show, - "series" => NodeKind::Series, - "season" => NodeKind::Season, - "episode" => NodeKind::Episode, + "movie" => KIND_MOVIE, + "video" => KIND_VIDEO, + "music" => KIND_MUSIC, + "short_form_video" => KIND_SHORTFORMVIDEO, + "collection" => KIND_COLLECTION, + "channel" => KIND_CHANNEL, + "show" => KIND_SHOW, + "series" => KIND_SERIES, + "season" => KIND_SEASON, + "episode" => KIND_EPISODE, _ => bail!("unknown node kind"), }; ct.db.update_node_init(node, |node| { |