-
-
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.
Merge pull request #3 from tsirysndr/feat/ContentDirectory
feat: add support for `Browse` action
- Loading branch information
Showing
6 changed files
with
327 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
/Cargo.lock | ||
*.xml |
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,31 @@ | ||
use futures_util::StreamExt; | ||
use upnp_client::{ | ||
device_client::DeviceClient, discovery::discover_pnp_locations, | ||
media_server::MediaServerClient, types::Device, | ||
}; | ||
|
||
const KODI_MEDIA_SERVER: &str = "Kodi - Media Server"; | ||
|
||
#[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_SERVER.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_server_client = MediaServerClient::new(device_client); | ||
let results = media_server_client | ||
.browse("0", "BrowseDirectChildren") | ||
.await?; | ||
println!("{:#?}", results); | ||
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
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,83 @@ | ||
use std::collections::HashMap; | ||
|
||
use crate::{ | ||
device_client::DeviceClient, | ||
parser::parse_browse_response, | ||
types::{Container, Item}, | ||
}; | ||
use anyhow::Error; | ||
pub struct MediaServerClient { | ||
device_client: DeviceClient, | ||
} | ||
|
||
impl MediaServerClient { | ||
pub fn new(device_client: DeviceClient) -> Self { | ||
Self { device_client } | ||
} | ||
|
||
pub async fn browse( | ||
&self, | ||
object_id: &str, | ||
browse_flag: &str, | ||
) -> Result<(Vec<Container>, Vec<Item>), Error> { | ||
let mut params = HashMap::new(); | ||
params.insert("ObjectID".to_string(), object_id.to_string()); | ||
params.insert("BrowseFlag".to_string(), browse_flag.to_string()); | ||
params.insert("Filter".to_string(), "*".to_string()); | ||
params.insert("StartingIndex".to_string(), "0".to_string()); | ||
params.insert("RequestedCount".to_string(), "0".to_string()); | ||
params.insert("SortCriteria".to_string(), "".to_string()); | ||
|
||
let response = self | ||
.device_client | ||
.call_action("ContentDirectory", "Browse", params) | ||
.await?; | ||
|
||
Ok(parse_browse_response(&response)?) | ||
} | ||
|
||
pub async fn get_sort_capabilities(&self) -> Result<(), Error> { | ||
let params = HashMap::new(); | ||
self.device_client | ||
.call_action("ContentDirectory", "GetSortCapabilities", params) | ||
.await?; | ||
|
||
todo!() | ||
} | ||
|
||
pub async fn get_system_update_id(&self) -> Result<(), Error> { | ||
let params = HashMap::new(); | ||
self.device_client | ||
.call_action("ContentDirectory", "GetSystemUpdateID", params) | ||
.await?; | ||
|
||
todo!() | ||
} | ||
|
||
pub async fn get_search_capabilities(&self) -> Result<(), Error> { | ||
let params = HashMap::new(); | ||
self.device_client | ||
.call_action("ContentDirectory", "GetSearchCapabilities", params) | ||
.await?; | ||
|
||
todo!() | ||
} | ||
|
||
pub async fn search(&self) -> Result<(), Error> { | ||
let params = HashMap::new(); | ||
self.device_client | ||
.call_action("ContentDirectory", "Search", params) | ||
.await?; | ||
|
||
todo!() | ||
} | ||
|
||
pub async fn update_object(&self) -> Result<(), Error> { | ||
let params = HashMap::new(); | ||
self.device_client | ||
.call_action("ContentDirectory", "UpdateObject", params) | ||
.await?; | ||
|
||
todo!() | ||
} | ||
} |
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