From 418b0b7cbec0cc10178a90be7d38877f52888718 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Fri, 23 Jan 2026 12:32:18 +0100 Subject: [PATCH] Add logging to container tree building and station item creation This commit adds conditional logging to the container tree building process and station item creation in the radio france source. The logging includes information about the number of groups, standalone stations, webradios, and local radios being processed. It also logs when using cached items and when starting metadata refresh tasks. The logging is enabled only when the 'logging' feature is activated. --- pmomediaserver/Cargo.toml | 1 + pmoradiofrance/src/source.rs | 48 ++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/pmomediaserver/Cargo.toml b/pmomediaserver/Cargo.toml index 82d65fa4..27f46c4b 100644 --- a/pmomediaserver/Cargo.toml +++ b/pmomediaserver/Cargo.toml @@ -58,5 +58,6 @@ radiofrance = [ "api", "dep:pmoradiofrance", "pmoradiofrance/server", + "pmoradiofrance/logging", "dep:pmoconfig" ] diff --git a/pmoradiofrance/src/source.rs b/pmoradiofrance/src/source.rs index 4b047066..0024811b 100644 --- a/pmoradiofrance/src/source.rs +++ b/pmoradiofrance/src/source.rs @@ -226,27 +226,62 @@ impl RadioFranceSource { /// Build the UPnP container tree dynamically from station data async fn build_container_tree(&self) -> Result { + #[cfg(feature = "logging")] + tracing::debug!("Building container tree"); + let stations = self.client.get_stations().await?; let groups = StationGroups::from_stations(stations); + #[cfg(feature = "logging")] + tracing::debug!( + "Groups: {} standalone, {} with webradios, {} local radios", + groups.standalone.len(), + groups.with_webradios.len(), + groups.local_radios.len() + ); + let mut containers = Vec::new(); let mut items = Vec::new(); // 1. Standalone stations → direct items (avec appels API) + #[cfg(feature = "logging")] + tracing::debug!( + "Building {} standalone station items", + groups.standalone.len() + ); + for station in &groups.standalone { items.push(self.build_station_item(station).await?); } // 2. Stations with webradios → containers + #[cfg(feature = "logging")] + tracing::debug!("Building {} group containers", groups.with_webradios.len()); + for group in &groups.with_webradios { + #[cfg(feature = "logging")] + tracing::debug!("Building container for group: {}", group.main.name); containers.push(self.build_station_container(group).await?); } // 3. Local radios → single "Radios ICI" container + #[cfg(feature = "logging")] + tracing::debug!( + "Building ICI container with {} local radios", + groups.local_radios.len() + ); + if !groups.local_radios.is_empty() { containers.push(self.build_ici_container(&groups.local_radios).await?); } + #[cfg(feature = "logging")] + tracing::debug!( + "Container tree built: {} containers, {} items", + containers.len(), + items.len() + ); + Ok(Container { id: "radiofrance".to_string(), parent_id: "0".to_string(), @@ -304,10 +339,19 @@ impl RadioFranceSource { /// /// Fetches live metadata to create a complete item with stream URL. async fn build_station_item(&self, station: &Station) -> Result { + #[cfg(feature = "logging")] + tracing::debug!( + "Building station item for: {} ({})", + station.name, + station.slug + ); + let playlists = self.playlists.read().await; // If we already have this station in cache, use it if let Some(existing) = playlists.get(&station.slug) { + #[cfg(feature = "logging")] + tracing::debug!("Using cached item for: {}", station.slug); return Ok(existing.stream_item.clone()); } @@ -335,8 +379,8 @@ impl RadioFranceSource { playlists_write.insert(station.slug.clone(), playlist.clone()); drop(playlists_write); - // Start metadata refresh task - let _ = self.start_metadata_refresh(&station.slug).await; + // Note: We don't start metadata refresh here to avoid blocking during browse. + // Refresh will be started in resolve_uri() when the stream is actually played. Ok(playlist.stream_item) }