diff --git a/crates/upnp-serve/examples/upnp-stub-server.rs b/crates/upnp-serve/examples/upnp-stub-server.rs index cc393dd07..f70dd0523 100644 --- a/crates/upnp-serve/examples/upnp-stub-server.rs +++ b/crates/upnp-serve/examples/upnp-stub-server.rs @@ -6,12 +6,28 @@ use std::{ use anyhow::Context; use axum::routing::get; use librqbit_upnp_serve::{ - services::content_directory::browse::response::{Item, ItemOrContainer}, + services::content_directory::{ + browse::response::{Item, ItemOrContainer}, + ContentDirectoryBrowseProvider, + }, UpnpServer, UpnpServerOptions, }; use mime_guess::Mime; use tracing::{error, info}; +struct VecWrap(Vec); + +impl ContentDirectoryBrowseProvider for VecWrap { + fn browse_direct_children(&self, _parent_id: usize, _http_host: &str) -> Vec { + self.0.clone() + } + + fn browse_metadata(&self, _object_id: usize, _http_hostname: &str) -> Vec { + // TODO. Remove the vec provider from core code. + vec![] + } +} + #[tokio::main] async fn main() -> anyhow::Result<()> { if std::env::var("RUST_LOG").is_err() { @@ -20,14 +36,14 @@ async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init(); - let items: Vec = vec![ItemOrContainer::Item(Item { + let items = VecWrap(vec![ItemOrContainer::Item(Item { title: "Example".to_owned(), mime_type: Some(Mime::from_str("video/x-matroska")?), url: "http://192.168.0.165:3030/torrents/4/stream/0/file.mkv".to_owned(), id: 1, parent_id: 0, size: 1, - })]; + })]); const HTTP_PORT: u16 = 9005; const HTTP_PREFIX: &str = "/upnp"; diff --git a/crates/upnp-serve/src/services/content_directory.rs b/crates/upnp-serve/src/services/content_directory.rs index 303ecfbcd..1e7f4ce4f 100644 --- a/crates/upnp-serve/src/services/content_directory.rs +++ b/crates/upnp-serve/src/services/content_directory.rs @@ -147,6 +147,9 @@ pub mod browse { "#, items = envelope.items ); + + // This COULD have been done with CDATA, but some Samsung TVs don't like that, they want + // escaped XML instead. let items_encoded = quick_xml::escape::escape(items_encoded.as_ref()); format!( @@ -339,17 +342,6 @@ pub trait ContentDirectoryBrowseProvider: Send + Sync { fn browse_metadata(&self, object_id: usize, http_hostname: &str) -> Vec; } -impl ContentDirectoryBrowseProvider for Vec { - fn browse_direct_children(&self, _parent_id: usize, _http_host: &str) -> Vec { - self.clone() - } - - fn browse_metadata(&self, _object_id: usize, _http_hostname: &str) -> Vec { - // TODO. Remove the vec provider from core code. - vec![] - } -} - #[cfg(test)] mod tests { #[test]