Fix cover caching and playlist persistence in play_and_cache example
Améliore la gestion du cache des covers dans FlacCacheSink : - Remplace les avertissements génériques par des logs détaillés (debug/info/warn) - Corrige la gestion des erreurs en retirant le `let _ =` qui ignorait les résultats - Ajoute des logs de debug pour tracer le processus de mise en cache des covers - Améliore la gestion des erreurs avec des messages plus informatifs Corrige la playlist de l'exemple play_and_cache : - Remplace create_persistent_playlist par get_write_handle pour créer une playlist éphémère - Une playlist persistante n'est pas nécessaire pour cet exemple de démonstration
This commit is contained in:
@@ -19,7 +19,6 @@ use tokio::{
|
||||
sync::{mpsc, RwLock},
|
||||
};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tracing::warn;
|
||||
|
||||
/// Sink qui encode les `AudioSegment` reçus au format FLAC et les stocke dans le cache audio.
|
||||
///
|
||||
@@ -258,31 +257,43 @@ impl NodeLogic for FlacCacheSinkLogic {
|
||||
})?;
|
||||
|
||||
let url = match dest_metadata.read().await.get_cover_url().await {
|
||||
Ok(url) => url,
|
||||
Err(e) if e.is_transient() => None,
|
||||
Err(_) => {
|
||||
warn!("Cannot obtain cover for audio asset {}", pk);
|
||||
Ok(url) => {
|
||||
tracing::debug!("FlacCacheSink: Got cover URL for pk {}: {:?}", pk, url);
|
||||
url
|
||||
}
|
||||
Err(e) if e.is_transient() => {
|
||||
tracing::debug!("FlacCacheSink: Transient error getting cover URL for pk {}: {}", pk, e);
|
||||
None
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!("FlacCacheSink: Cannot obtain cover URL for audio asset {}: {}", pk, e);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
if url.is_some() {
|
||||
let _ = match self.covers
|
||||
.add_from_url(&url.unwrap(), self.collection.as_deref())
|
||||
if let Some(cover_url) = url {
|
||||
tracing::debug!("FlacCacheSink: Attempting to cache cover from URL: {}", cover_url);
|
||||
match self.covers
|
||||
.add_from_url(&cover_url, self.collection.as_deref())
|
||||
.await
|
||||
{
|
||||
Ok(pk_covers) => {
|
||||
dest_metadata
|
||||
tracing::info!("FlacCacheSink: Successfully cached cover for pk {} with cover pk {}", pk, pk_covers);
|
||||
if let Err(e) = dest_metadata
|
||||
.write()
|
||||
.await
|
||||
.set_cover_pk(Some(pk_covers))
|
||||
.await
|
||||
{
|
||||
tracing::error!("FlacCacheSink: Failed to set cover_pk for audio asset {}: {:?}", pk, e);
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
warn!("Cannot obtain cover for audio asset {}", pk);
|
||||
Ok(Some(()))
|
||||
Err(e) => {
|
||||
tracing::warn!("FlacCacheSink: Failed to cache cover for audio asset {}: {}", pk, e);
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
tracing::debug!("FlacCacheSink: No cover URL available for pk {}", pk);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,8 +129,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let playlist_id = format!("radio-paradise-ch{}", channel_id);
|
||||
tracing::info!("Creating playlist: {}", playlist_id);
|
||||
|
||||
// Créer la playlist (ou la vider si elle existe)
|
||||
let mut writer = playlist_manager.create_persistent_playlist(playlist_id.clone()).await?;
|
||||
// Créer une playlist éphémère (non persistante) pour cet exemple
|
||||
let mut writer = playlist_manager.get_write_handle(playlist_id.clone()).await?;
|
||||
writer.set_title(format!("Radio Paradise - Channel {}", channel_id)).await?;
|
||||
writer.flush().await?; // Vider la playlist si elle existait
|
||||
tracing::debug!("Playlist created and flushed");
|
||||
|
||||
Reference in New Issue
Block a user