blob: fe47290c65dc6c1b8dbf0bc77712ac48630b1da4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)
// }
|