Git Product home page Git Product logo

crab-dlna's Introduction

crab-dlna

CICD Version info

crab-dlna is a minimal UPnP/DLNA media streamer, available both as a standlone CLI (command line interface) application and a Rust library.

It allows you to play a local video file in your TV (or any other DLNA compatible device).

Features

  • Searching available DLNA devices in the local network
  • Streaming audio
  • Streaming video, with subtitle support

Installation

In the GitHub Releases of this repository we provide archives of precompiled binaries of crab-dlna, available for Linux, Windows, and macOS.

cargo

Installation via cargo is done by installing the crab-dlna crate:

# If required, update Rust on the stable channel
rustup update stable

cargo install crab-dlna

# Alternatively, --locked may be required due to how cargo install works
cargo install crab-dlna --locked

Usage (CLI)

You can list all the CLI commands by running:

crab-dlna --help

List

Scan compatible devices and list the available ones:

crab-dlna list

If your device is not being listed, you might need to increase the search timeout:

crab-dlna -t 20 list

Play

Play a video, automatically loading the subtitles if available, selecting a random device:

crab-dlna play That.Movie.mkv

Play a video, specifying the device through query (scan devices before playing):

crab-dlna play That.Movie.mkv -q "osmc"

Play a video, specifying the device through its exact location (no scan, faster):

crab-dlna play That.Movie.mkv -d "http://192.168.1.13:1082/"

Usage (library)

Add crab-dlna and tokio to your dependencies:

[dependencies] 
tokio = { version = "1", features = ["full"] }
crab-dlna = "0.2"

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 device

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
}

You can access the full documentation to see more details about the library.

License

Copyright (c) 2022 Gabriel Magno.

crab-dlna is made available under the terms of either the MIT License or the Apache License 2.0, at your option.

See the LICENSE-APACHE and LICENSE-MIT files for license details.

crab-dlna's People

Contributors

gabrielmagno avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.