amélioration de la webapp

This commit is contained in:
2025-10-19 13:42:29 +02:00
parent 756ae7f82c
commit 208fe8be76
179 changed files with 2426 additions and 1685 deletions

View File

@@ -5,7 +5,7 @@
//! cargo run -p pmoplaylist --example basic_usage
//! ```
use pmoplaylist::{FifoPlaylist, Track, DEFAULT_IMAGE};
use pmoplaylist::{DEFAULT_IMAGE, FifoPlaylist, Track};
#[tokio::main]
async fn main() {
@@ -27,26 +27,40 @@ async fn main() {
// 2. Ajouter des tracks
println!("2. Ajout de 3 tracks...");
let tracks = vec![
Track::new("track-1", "Bohemian Rhapsody", "http://example.com/queen/bohemian.flac")
.with_artist("Queen")
.with_album("A Night at the Opera")
.with_duration(354)
.with_image("http://example.com/covers/queen-anato.jpg"),
Track::new("track-2", "Stairway to Heaven", "http://example.com/zeppelin/stairway.mp3")
.with_artist("Led Zeppelin")
.with_album("Led Zeppelin IV")
.with_duration(482),
Track::new("track-3", "Hotel California", "http://example.com/eagles/hotel.flac")
.with_artist("Eagles")
.with_album("Hotel California")
.with_duration(391),
Track::new(
"track-1",
"Bohemian Rhapsody",
"http://example.com/queen/bohemian.flac",
)
.with_artist("Queen")
.with_album("A Night at the Opera")
.with_duration(354)
.with_image("http://example.com/covers/queen-anato.jpg"),
Track::new(
"track-2",
"Stairway to Heaven",
"http://example.com/zeppelin/stairway.mp3",
)
.with_artist("Led Zeppelin")
.with_album("Led Zeppelin IV")
.with_duration(482),
Track::new(
"track-3",
"Hotel California",
"http://example.com/eagles/hotel.flac",
)
.with_artist("Eagles")
.with_album("Hotel California")
.with_duration(391),
];
for track in tracks {
playlist.append_track(track.clone()).await;
println!(" ✓ Ajouté: {} - {}", track.title, track.artist.unwrap_or_default());
println!(
" ✓ Ajouté: {} - {}",
track.title,
track.artist.unwrap_or_default()
);
}
println!("\n Total tracks: {}", playlist.len().await);
@@ -60,12 +74,15 @@ async fn main() {
let track = Track::new(
format!("track-{}", i),
format!("Song Number {}", i),
format!("http://example.com/songs/{}.mp3", i)
format!("http://example.com/songs/{}.mp3", i),
);
playlist.append_track(track).await;
}
println!(" ✓ Total tracks (limité par capacité): {}", playlist.len().await);
println!(
" ✓ Total tracks (limité par capacité): {}",
playlist.len().await
);
// Afficher les tracks actuels
let items = playlist.get_items(0, 10).await;
@@ -99,15 +116,16 @@ async fn main() {
println!(" - Parent ID: {}", container.parent_id);
println!(" - Title: {}", container.title);
println!(" - Class: {}", container.class);
println!(" - Child Count: {}\n", container.child_count.unwrap_or_default());
println!(
" - Child Count: {}\n",
container.child_count.unwrap_or_default()
);
// 7. Générer des Items DIDL-Lite
println!("7. Génération des Items DIDL-Lite...");
let didl_items = playlist.as_objects(
0,
10,
Some("http://myserver/api/default-image")
).await;
let didl_items = playlist
.as_objects(0, 10, Some("http://myserver/api/default-image"))
.await;
println!(" Items DIDL-Lite:");
for (idx, item) in didl_items.iter().enumerate() {
@@ -134,7 +152,10 @@ async fn main() {
// 8. Image par défaut
println!("\n8. Image par défaut...");
let default_image = playlist.default_image().await;
println!(" ✓ Taille de l'image par défaut: {} bytes", default_image.len());
println!(
" ✓ Taille de l'image par défaut: {} bytes",
default_image.len()
);
println!(" (Cette image peut être servie via un endpoint HTTP)\n");
// 9. Vider la playlist

View File

@@ -8,7 +8,7 @@
//! cargo run -p pmoplaylist --example http_server_integration
//! ```
use pmoplaylist::{FifoPlaylist, Track, DEFAULT_IMAGE};
use pmoplaylist::{DEFAULT_IMAGE, FifoPlaylist, Track};
use std::sync::Arc;
#[tokio::main]
@@ -35,17 +35,19 @@ async fn main() {
];
for (idx, (artist, title, album, duration)) in initial_tracks.iter().enumerate() {
playlist.append_track(
Track::new(
format!("track-{}", idx),
*title,
format!("http://media.server/music/{}.flac", idx)
playlist
.append_track(
Track::new(
format!("track-{}", idx),
*title,
format!("http://media.server/music/{}.flac", idx),
)
.with_artist(*artist)
.with_album(*album)
.with_duration(*duration)
.with_image(format!("http://media.server/covers/{}.jpg", idx)),
)
.with_artist(*artist)
.with_album(*album)
.with_duration(*duration)
.with_image(format!("http://media.server/covers/{}.jpg", idx))
).await;
.await;
println!("{} - {}", artist, title);
}
println!();
@@ -72,7 +74,7 @@ async fn main() {
let new_track = Track::new(
"track-new-1",
"Stairway to Heaven",
"http://media.server/music/stairway.flac"
"http://media.server/music/stairway.flac",
)
.with_artist("Led Zeppelin")
.with_album("Led Zeppelin IV")
@@ -115,17 +117,18 @@ async fn simulate_get_container(playlist: Arc<FifoPlaylist>) {
println!(" \"parentId\": \"{}\",", container.parent_id);
println!(" \"title\": \"{}\",", container.title);
println!(" \"class\": \"{}\",", container.class);
println!(" \"childCount\": {}", container.child_count.unwrap_or_default());
println!(
" \"childCount\": {}",
container.child_count.unwrap_or_default()
);
println!(" }}");
}
/// Simule GET /playlist/items?offset=X&count=Y
async fn simulate_get_items(playlist: Arc<FifoPlaylist>, offset: usize, count: usize) {
let items = playlist.as_objects(
offset,
count,
Some("http://media.server/api/default-image")
).await;
let items = playlist
.as_objects(offset, count, Some("http://media.server/api/default-image"))
.await;
println!(" Response: {} items", items.len());
println!(" [");
@@ -133,8 +136,14 @@ async fn simulate_get_items(playlist: Arc<FifoPlaylist>, offset: usize, count: u
println!(" {{");
println!(" \"id\": \"{}\",", item.id);
println!(" \"title\": \"{}\",", item.title);
println!(" \"artist\": \"{}\",", item.artist.as_deref().unwrap_or(""));
println!(" \"album\": \"{}\",", item.album.as_deref().unwrap_or(""));
println!(
" \"artist\": \"{}\",",
item.artist.as_deref().unwrap_or("")
);
println!(
" \"album\": \"{}\",",
item.album.as_deref().unwrap_or("")
);
println!(" \"class\": \"{}\",", item.class);
if !item.resources.is_empty() {
println!(" \"uri\": \"{}\",", item.resources[0].url);
@@ -175,7 +184,8 @@ async fn simulate_add_track(playlist: Arc<FifoPlaylist>, track: Track) {
let new_update_id = playlist.update_id().await;
println!(" Track added: {} - {}",
println!(
" Track added: {} - {}",
track.artist.as_deref().unwrap_or("Unknown"),
track.title
);

View File

@@ -10,7 +10,7 @@
//! cargo run -p pmoplaylist --example radio_streaming
//! ```
use pmoplaylist::{FifoPlaylist, Track, DEFAULT_IMAGE};
use pmoplaylist::{DEFAULT_IMAGE, FifoPlaylist, Track};
use std::time::Duration;
use tokio::time::sleep;
@@ -42,26 +42,46 @@ async fn main() {
let tracks_data = vec![
("Radiohead", "Paranoid Android", "OK Computer", 383),
("Massive Attack", "Teardrop", "Mezzanine", 329),
("Pink Floyd", "Shine On You Crazy Diamond", "Wish You Were Here", 810),
(
"Pink Floyd",
"Shine On You Crazy Diamond",
"Wish You Were Here",
810,
),
("Portishead", "Glory Box", "Dummy", 305),
("Dire Straits", "Sultans of Swing", "Dire Straits", 349),
("The Cure", "Pictures of You", "Disintegration", 428),
("David Bowie", "Heroes", "Heroes", 371),
("Talking Heads", "Once in a Lifetime", "Remain in Light", 259),
(
"Talking Heads",
"Once in a Lifetime",
"Remain in Light",
259,
),
("Fleetwood Mac", "Dreams", "Rumours", 257),
("The Smiths", "There Is a Light That Never Goes Out", "The Queen Is Dead", 244),
(
"The Smiths",
"There Is a Light That Never Goes Out",
"The Queen Is Dead",
244,
),
("Joy Division", "Love Will Tear Us Apart", "Closer", 206),
("New Order", "Blue Monday", "Power, Corruption & Lies", 448),
("Depeche Mode", "Enjoy the Silence", "Violator", 376),
("R.E.M.", "Losing My Religion", "Out of Time", 269),
("U2", "Where the Streets Have No Name", "The Joshua Tree", 337),
(
"U2",
"Where the Streets Have No Name",
"The Joshua Tree",
337,
),
];
for (idx, (artist, title, album, duration)) in tracks_data.iter().enumerate() {
let track = Track::new(
format!("radio-track-{}", idx),
*title,
format!("http://stream.radioparadise.com/track/{}", idx)
format!("http://stream.radioparadise.com/track/{}", idx),
)
.with_artist(*artist)
.with_album(*album)
@@ -94,9 +114,7 @@ async fn main() {
if current_update_id != last_update_id {
println!(
"👁️ [MONITOR] Changement détecté! Update ID: {}{} | Tracks: {}",
last_update_id,
current_update_id,
count
last_update_id, current_update_id, count
);
last_update_id = current_update_id;
}
@@ -125,7 +143,11 @@ async fn main() {
let history = radio_client.get_items(0, 10).await;
let update_id = radio_client.update_id().await;
println!("📱 [CLIENT] Consultation #{} (Update ID: {})", i + 1, update_id);
println!(
"📱 [CLIENT] Consultation #{} (Update ID: {})",
i + 1,
update_id
);
println!(" Historique actuel ({} tracks):", history.len());
for (idx, track) in history.iter().enumerate() {
@@ -140,7 +162,10 @@ async fn main() {
let container = radio_client.as_container().await;
println!(" Container ID: {}", container.id);
println!(" Title: {}", container.title);
println!(" Child Count: {}", container.child_count.unwrap_or_default());
println!(
" Child Count: {}",
container.child_count.unwrap_or_default()
);
println!("\n📱 [CLIENT] Fin de la consultation");
});