diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-18 23:09:05 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-18 23:09:05 +0200 |
commit | 5b6fd021cc84ae7f5e1719ff398ff4627493a13c (patch) | |
tree | ca3ff6936d56bee8cc53a82c838175b1b4576907 | |
parent | 6ca78512fe08228c419bcdd06fd774c7a3b3e69f (diff) | |
download | jellything-5b6fd021cc84ae7f5e1719ff398ff4627493a13c.tar jellything-5b6fd021cc84ae7f5e1719ff398ff4627493a13c.tar.bz2 jellything-5b6fd021cc84ae7f5e1719ff398ff4627493a13c.tar.zst |
fpcalc wrapper
-rw-r--r-- | import/src/acoustid.rs | 38 | ||||
-rw-r--r-- | import/src/lib.rs | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/import/src/acoustid.rs b/import/src/acoustid.rs new file mode 100644 index 0000000..fe47290 --- /dev/null +++ b/import/src/acoustid.rs @@ -0,0 +1,38 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2025 metamuffin <metamuffin.org> +*/ +use anyhow::Result; +use bincode::{Decode, Encode}; +use jellybase::cache::async_cache_memory; +use serde::Deserialize; +use std::{path::Path, process::Stdio, sync::Arc}; +use tokio::{io::AsyncReadExt, process::Command}; + +#[derive(Debug, Encode, Decode, Deserialize)] +pub(crate) struct Fingerprint { + duration: f32, + fingerprint: String, +} + +pub(crate) async fn acoustid_fingerprint(path: &Path) -> Result<Arc<Fingerprint>> { + async_cache_memory(&["fpcalc", &path.to_string_lossy()], || async move { + let child = Command::new("fpcalc") + .arg("-json") + .arg(path) + .stdout(Stdio::piped()) + .spawn()?; + + let mut buf = Vec::new(); + child.stdout.unwrap().read_to_end(&mut buf).await?; + let out: Fingerprint = serde_json::from_slice(&buf)?; + + Ok(out) + }) + .await +} + +// pub(crate) async fn acoustid_mbid(fingerprint: Fingerprint) -> Result<Arc<Option<String>>> { +// async_cache_memory(&["api-acoustid", fingerprint], generate) +// } diff --git a/import/src/lib.rs b/import/src/lib.rs index 78a99c3..0ac48ae 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -37,6 +37,7 @@ use trakt::Trakt; pub mod infojson; pub mod tmdb; pub mod trakt; +pub mod acoustid; static IMPORT_SEM: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::new(1)); pub static IMPORT_ERRORS: RwLock<Vec<String>> = RwLock::const_new(Vec::new()); |