-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
793 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,16 @@ authors = ["Tsiry Sandratraina <[email protected]>"] | |
categories = ["command-line-utilities", "network-programming"] | ||
keywords = ["upnp", "client", "tokio", "dlna"] | ||
description = "A simple UPnP client written in Rust" | ||
|
||
[[example]] | ||
name = "discover" | ||
path = "examples/discover.rs" | ||
|
||
[[example]] | ||
name = "media-renderer-client" | ||
path = "examples/media_renderer_client.rs" | ||
|
||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
@@ -23,3 +33,6 @@ serde_json = "1.0.91" | |
socket2 = "0.4.7" | ||
surf = { version = "2.3.2", features = ["h1-client-rustls"], default-features = false} | ||
tokio = { version = "1.24.2", features = ["tokio-macros", "macros", "rt", "rt-multi-thread"] } | ||
url = "2.3.1" | ||
xml-builder = "0.5.1" | ||
xml-rs = "0.8.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use futures_util::StreamExt; | ||
use upnp_client::{ | ||
device_client::DeviceClient, | ||
discovery::discover_pnp_locations, | ||
media_renderer::MediaRendererClient, | ||
types::{Device, LoadOptions, Metadata, ObjectClass}, | ||
}; | ||
|
||
const KODI_MEDIA_RENDERER: &str = "Kodi - Media Renderer"; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let devices = discover_pnp_locations(); | ||
tokio::pin!(devices); | ||
|
||
let mut kodi_device: Option<Device> = None; | ||
while let Some(device) = devices.next().await { | ||
// Select the first Kodi device found | ||
if device.model_description == Some(KODI_MEDIA_RENDERER.to_string()) { | ||
kodi_device = Some(device); | ||
break; | ||
} | ||
} | ||
|
||
let kodi_device = kodi_device.unwrap(); | ||
let device_client = DeviceClient::new(&kodi_device.location).connect().await?; | ||
let media_renderer = MediaRendererClient::new(device_client); | ||
|
||
let options = LoadOptions { | ||
dlna_features: Some( | ||
"DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000" | ||
.to_string(), | ||
), | ||
content_type: Some("video/mp4".to_string()), | ||
metadata: Some(Metadata { | ||
title: "Big Buck Bunny".to_string(), | ||
..Default::default() | ||
}), | ||
autoplay: true, | ||
object_class: Some(ObjectClass::Video), | ||
..Default::default() | ||
}; | ||
|
||
let media_url = | ||
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; | ||
|
||
media_renderer.load(media_url, options).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.