From 78792e1d691c24159c988924ffc99eb7fb6d690d Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Sat, 18 Oct 2025 23:51:36 +0200 Subject: [PATCH] ebuggage transcodage audio en flac --- .DS_Store | Bin 14340 -> 14340 bytes pmoaudiocache/src/cache.rs | 17 ----------------- pmocache/src/cache_trait.rs | 32 ++++++++++++++++++++++++++------ pmocovers/src/cache.rs | 18 ------------------ pmocovers/src/db.rs | 7 ------- pmoparadise/src/source.rs | 6 +++--- pmoupnp/src/cache_registry.rs | 13 +++++++++++-- 7 files changed, 40 insertions(+), 53 deletions(-) delete mode 100644 pmocovers/src/db.rs diff --git a/.DS_Store b/.DS_Store index 1596fb0bf79ff731a924cb99710a80fb3ee69f13..8a936c1c4c56cd287ffa1fd663fbdb47758aca4e 100644 GIT binary patch delta 24 fcmZoEXeroGrNGM0$ diff --git a/pmoaudiocache/src/cache.rs b/pmoaudiocache/src/cache.rs index eafb3843..32cfb2ab 100644 --- a/pmoaudiocache/src/cache.rs +++ b/pmoaudiocache/src/cache.rs @@ -201,20 +201,3 @@ pub fn get_metadata(cache: &Cache, pk: &str) -> Result) -> String { - if let Some(p) = param { - format!("/audio/tracks/{}/{}", pk, p) - } else { - format!("/audio/tracks/{}", pk) - } -} diff --git a/pmocache/src/cache_trait.rs b/pmocache/src/cache_trait.rs index 60c212b9..f6453121 100644 --- a/pmocache/src/cache_trait.rs +++ b/pmocache/src/cache_trait.rs @@ -1,6 +1,9 @@ use anyhow::Result; use sha1::{Digest, Sha1}; -use std::{path::{Path, PathBuf}, sync::Arc}; +use std::{ + path::{Path, PathBuf}, + sync::Arc, +}; use crate::{CacheConfig, DB}; @@ -8,9 +11,8 @@ use crate::{CacheConfig, DB}; /// /// Définit l'interface commune pour tous les types de caches (images, audio, etc.) pub trait FileCache: Send + Sync { - fn get_cache_dir(&self) -> &Path; - fn get_database(&self) -> Arc; + fn get_database(&self) -> Arc; /// Valide les données avant de les stocker dans le cache /// @@ -44,7 +46,7 @@ pub trait FileCache: Send + Sync { C::default_param() } - /// Retourne l'extension des fichiers + /// Retourne l'extension des fichiers fn file_extension(&self) -> &'static str { C::file_extension() } @@ -66,7 +68,26 @@ pub trait FileCache: Send + Sync { /// /// Format: `{pk}.{qualificatif}.{extension}` fn file_path_with_qualifier(&self, pk: &str, qualifier: &str) -> PathBuf { - self.get_cache_dir().join(format!("{}.{}.{}", pk, qualifier, C::file_extension())) + self.get_cache_dir() + .join(format!("{}.{}.{}", pk, qualifier, C::file_extension())) + } + + /// Retourne la route relative pour accéder à un item du cache + /// + /// # Arguments + /// + /// * `pk` - Clé primaire de la piste + /// * `param` - Paramètre optionnel (ex: "orig", "128k", etc.) + /// + /// # Returns + /// + /// Route relative (ex: "/audio/flac/abc123" ou "/audio/tracks/abc123/orig") + fn route_for(&self, pk: &str, param: Option<&str>) -> String { + if let Some(p) = param { + format!("/{}/{}/{}/{}", C::cache_name(), C::cache_type(), pk, p) + } else { + format!("/{}/{}/{}", C::cache_name(), C::cache_type(), pk) + } } /// Télécharge un fichier depuis une URL et l'ajoute au cache @@ -124,7 +145,6 @@ pub trait FileCache: Send + Sync { /// Consolide le cache en supprimant les orphelins et en re-téléchargeant les fichiers manquants async fn consolidate(&self) -> Result<()>; - } /// Génère une clé primaire à partir d'une URL diff --git a/pmocovers/src/cache.rs b/pmocovers/src/cache.rs index aaf8ba42..50b4e424 100644 --- a/pmocovers/src/cache.rs +++ b/pmocovers/src/cache.rs @@ -79,21 +79,3 @@ pub fn new_cache(dir: &str, limit: usize) -> Result { let transformer_factory = Arc::new(|| create_webp_transformer()); Cache::with_transformer(dir, limit, Some(transformer_factory)) } - -/// Retourne la route relative pour accéder à une couverture -/// -/// # Arguments -/// -/// * `pk` - Clé primaire de l'image -/// * `size` - Taille optionnelle de l'image -/// -/// # Returns -/// -/// Route relative (ex: "/covers/images/abc123" ou "/covers/images/abc123/300") -pub fn route_for(pk: &str, size: Option) -> String { - if let Some(s) = size { - format!("/covers/images/{}/{}", pk, s) - } else { - format!("/covers/images/{}", pk) - } -} diff --git a/pmocovers/src/db.rs b/pmocovers/src/db.rs deleted file mode 100644 index 64767b9d..00000000 --- a/pmocovers/src/db.rs +++ /dev/null @@ -1,7 +0,0 @@ -//! Module de compatibilité pour l'ancien module db -//! -//! Ce module réexporte les types de `pmocache::db` pour maintenir -//! la compatibilité avec l'API existante. - -// Réexporter les types de pmocache -pub use pmocache::db::{CacheEntry, DB}; diff --git a/pmoparadise/src/source.rs b/pmoparadise/src/source.rs index b3a88abc..c7f83f3f 100644 --- a/pmoparadise/src/source.rs +++ b/pmoparadise/src/source.rs @@ -634,11 +634,11 @@ mod tests { std::fs::create_dir_all(&audio_dir).ok(); let cover_cache = Arc::new( - pmocovers::Cache::new(cover_dir.to_str().unwrap(), 100, "http://localhost:8080") - .await.unwrap() + pmocovers::Cache::new(cover_dir.to_str().unwrap(), 100) + .unwrap() ); let audio_cache = Arc::new( - pmoaudiocache::new_cache(audio_dir.to_str().unwrap(), 100, "http://localhost:8080") + pmoaudiocache::new_cache(audio_dir.to_str().unwrap(), 100) .unwrap() ); diff --git a/pmoupnp/src/cache_registry.rs b/pmoupnp/src/cache_registry.rs index 88c648aa..44dbc163 100644 --- a/pmoupnp/src/cache_registry.rs +++ b/pmoupnp/src/cache_registry.rs @@ -9,6 +9,7 @@ use std::sync::Arc; use once_cell::sync::Lazy; +use pmocache::FileCache; use std::sync::RwLock; use pmocovers::Cache as CoverCache; use pmoaudiocache::Cache as AudioCache; @@ -82,7 +83,13 @@ impl CacheRegistry { let base_url = self.base_url .as_ref() .ok_or_else(|| anyhow::anyhow!("Base URL not set in CacheRegistry"))?; - let route = pmocovers::cache::route_for(pk, size); + let cache = get_cover_cache() + .ok_or_else(|| anyhow::anyhow!("No registred cover cache"))?; + let param= match size { + Some(size_) => Some(size_.to_string()), + None => None + }; + let route = cache.route_for(pk, param.as_deref()); Ok(format!("{}{}", base_url, route)) } @@ -100,7 +107,9 @@ impl CacheRegistry { let base_url = self.base_url .as_ref() .ok_or_else(|| anyhow::anyhow!("Base URL not set in CacheRegistry"))?; - let route = pmoaudiocache::cache::route_for(pk, param); + let cache = get_audio_cache() + .ok_or_else(|| anyhow::anyhow!("No registred audio cache"))?; + let route = cache.route_for(pk, param); Ok(format!("{}{}", base_url, route)) } }