Correction de la source radio paradise pour avoir un sous dossier par canal

This commit is contained in:
2025-10-19 18:14:28 +02:00
parent fa3999569a
commit eea5829776
6 changed files with 748 additions and 448 deletions

2
Cargo.lock generated
View File

@@ -2479,6 +2479,7 @@ dependencies = [
"axum",
"bytes",
"claxon",
"flacenc",
"futures",
"hound",
"pmoaudiocache",
@@ -2491,6 +2492,7 @@ dependencies = [
"reqwest",
"serde",
"serde_json",
"symphonia",
"tempfile",
"thiserror 1.0.69",
"tokio",

View File

@@ -90,9 +90,7 @@ impl CacheInput {
pub async fn bytes(&mut self) -> Result<Bytes, String> {
match &mut self.inner {
CacheInputInner::Http {
response,
buffer,
..
response, buffer, ..
} => {
if let Some(bytes) = buffer.clone() {
return Ok(bytes);
@@ -130,9 +128,7 @@ impl CacheInput {
pub fn into_byte_stream(self) -> ByteStream {
match self.inner {
CacheInputInner::Http {
response,
buffer,
..
response, buffer, ..
} => {
if let Some(response) = response {
Box::pin(

View File

@@ -27,6 +27,7 @@ anyhow = "1.0"
# Streaming de bytes
bytes = "1.5"
futures = "0.3"
flacenc = "0.4"
# Logging
tracing = "0.1"
@@ -34,6 +35,9 @@ tracing = "0.1"
# URL manipulation
url = "2.5"
# Audio decoding/encoding
symphonia = { version = "0.5", features = ["all"] }
# Per-track feature dependencies
claxon = { version = "0.4", optional = true }
hound = { version = "3.5", optional = true }

View File

@@ -92,6 +92,19 @@ impl RadioParadiseClient {
self.channel
}
fn block_base_for_channel(channel: u8) -> String {
format!("https://apps.radioparadise.com/blocks/chan/{}", channel)
}
/// Clone the client with a different channel while preserving other settings.
pub fn clone_with_channel(&self, channel: u8) -> Self {
let mut cloned = self.clone();
cloned.channel = channel;
cloned.block_base = Self::block_base_for_channel(channel);
cloned.next_block_url = None;
cloned
}
/// Get a block by event ID
///
/// If `event` is None, returns the current block.
@@ -123,7 +136,8 @@ impl RadioParadiseClient {
url.query_pairs_mut()
.append_pair("bitrate", &self.bitrate.as_u8().to_string())
.append_pair("info", "true");
.append_pair("info", "true")
.append_pair("channel", &self.channel.to_string());
if let Some(event_id) = event {
url.query_pairs_mut()
@@ -348,10 +362,16 @@ impl ClientBuilder {
builder.build()?
};
let block_base = if self.block_base == DEFAULT_BLOCK_BASE {
RadioParadiseClient::block_base_for_channel(self.channel)
} else {
self.block_base.clone()
};
Ok(RadioParadiseClient {
client,
api_base: self.api_base,
block_base: self.block_base,
block_base,
image_base: self.image_base,
bitrate: self.bitrate,
channel: self.channel,

File diff suppressed because it is too large Load Diff

View File

@@ -23,6 +23,7 @@ use pmoaudiocache::{AudioMetadata, Cache as AudioCache};
use pmocovers::Cache as CoverCache;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::io::AsyncRead;
use tokio::sync::RwLock;
/// Métadonnées d'une piste en cache
@@ -216,6 +217,32 @@ impl SourceCacheManager {
Ok(pk)
}
/// Cache un flux audio via un reader asynchrone
pub async fn cache_audio_from_reader<R>(
&self,
source_uri: &str,
reader: R,
length: Option<u64>,
) -> Result<String>
where
R: AsyncRead + Send + Unpin + 'static,
{
let pk = self
.audio_cache
.add_from_reader(source_uri, reader, length, Some(&self.collection_id))
.await
.map_err(|e| MusicSourceError::CacheError(e.to_string()))?;
Ok(pk)
}
/// Attend que le fichier audio correspondant soit complètement disponible
pub async fn wait_audio_ready(&self, pk: &str) -> Result<()> {
self.audio_cache
.wait_until_finished(pk)
.await
.map_err(|e| MusicSourceError::CacheError(e.to_string()))
}
/// Mettre à jour les métadonnées d'une piste
///
/// Enregistre ou met à jour les métadonnées de cache pour une piste.