Expand description
crab-dlna is a minimal UPnP/DLNA media streamer.
It allows you to play a local video file in your TV (or any other DLNA compatible device).
This crate provides both a library and a command line tool.
§Features
- Searching available DLNA devices in the local network
- Streaming audio
- Streaming video, with subtitle support
§Example: discover and list devices
crab-dlna provides a function to discover a list devices in the network.
use crab_dlna::Render;
#[tokio::main]
async fn main() {
let discover_timeout_secs = 5;
let renders_discovered = Render::discover(discover_timeout_secs).await.unwrap();
for render in renders_discovered {
println!("{}", render);
}
}§Example: play a video in a render
We can specify a DLNA device render trough a query string, and then play a certain video in it, automatically detecting the subtitle file.
use std::path::PathBuf;
use crab_dlna::{
Render,
RenderSpec,
MediaStreamingServer,
STREAMING_PORT_DEFAULT,
get_local_ip,
infer_subtitle_from_video,
Error,
play,
};
#[tokio::main]
async fn main() -> Result<(), Error> {
let discover_timeout_secs = 5;
let render_spec = RenderSpec::Query(discover_timeout_secs, "Kodi".to_string());
let render = Render::new(render_spec).await?;
let host_ip = get_local_ip().await?;
let host_port = STREAMING_PORT_DEFAULT;
let video_path = PathBuf::from("/home/crab/Videos/my_video.mp4");
let inferred_subtitle_path = infer_subtitle_from_video(&video_path);
let media_streaming_server = MediaStreamingServer::new(
&video_path,
&inferred_subtitle_path,
&host_ip,
&host_port,
)?;
play(render, media_streaming_server).await
}§Technical Details
crab-dlna is basically a one-file DLNA MediaServer and a self DLNA MediaController.
How does list work?
- Issue an SSDP M-Search broadcast message in the network
- Capture the responses and register the devices
- Filter only devices that provide UPnP’s AVTransport service
How does play work?
- Setup an HTTP server to provide the media files to be streamed (including subtitles)
- Send a
SetAVTransportURImessage to the device, specifying the HTTP URLs of the media files - Send a
Playmessage to the device
Modules§
- cli
- Command line interface
Structs§
- Media
Streaming Server - A media streaming server
- Render
- A DLNA device which is capable of AVTransport actions.
Enums§
- Error
- Errors that can happen inside crab-dlna
- Render
Spec - An specification of a DLNA render device.
Constants§
- STREAMING_
PORT_ DEFAULT - Default port to use for the streaming server
Functions§
- get_
local_ ip - Identifies the local serve IP address.
- infer_
subtitle_ from_ video - Infer the subtitle file path from the video file path.
- play
- Plays a media file in a DLNA compatible device render, according to the render and media streaming server provided