diff options
author | metamuffin <metamuffin@disroot.org> | 2023-12-22 00:29:11 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-12-22 00:29:11 +0100 |
commit | 826c61c9612e855b19c3adb0e93d80bbfb4dc903 (patch) | |
tree | f7fb1b900b3fa5ced46de392a47756c3ca5cc398 /import | |
parent | 3a29113e965a94bdef06655f1583cc6e86edd606 (diff) | |
download | jellything-826c61c9612e855b19c3adb0e93d80bbfb4dc903.tar jellything-826c61c9612e855b19c3adb0e93d80bbfb4dc903.tar.bz2 jellything-826c61c9612e855b19c3adb0e93d80bbfb4dc903.tar.zst |
rework import system pt. 2
Diffstat (limited to 'import')
-rw-r--r-- | import/Cargo.toml | 4 | ||||
-rw-r--r-- | import/src/lib.rs | 65 |
2 files changed, 64 insertions, 5 deletions
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 <metamuffin.org> */ #![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<Semaphore> = 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 +} |