rsmediainfo 0.2.0

Rust wrapper for MediaInfo library
//! Example that requests the underlying library's raw JSON output instead
//! of a structured `MediaInfo` value.
//!
//! Setting `ParseOptions::output("JSON")` makes the parse call return the
//! verbatim text payload the library would emit on its own command line,
//! ready to pipe into another tool, write to disk, or send over the wire.
//! Other accepted output values include `""` (or `"text"`) for the default
//! human-readable text report, `"XML"` / `"OLDXML"` for XML, and
//! `%`-delimited templates such as `"General;%FileSize%"`.
//!
//! Run with:
//!
//! ```text
//! cargo run --example parse_raw_output -- tests/data/sample.mp4
//! ```

use rsmediainfo::{MediaInfo, ParseOptions, ParseOutput};
use std::env;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut args = env::args().skip(1);
    let path = args.next().ok_or("usage: parse_raw_output <media_path>")?;

    let opts = ParseOptions::new().output("JSON");
    let result = MediaInfo::parse_with_options(path.as_str(), &opts)?;

    // With `output` set, the parse call returns raw text rather than a
    // structured `MediaInfo`. The other variant of `ParseOutput` would only
    // appear if the option were left unset.
    if let ParseOutput::Output(text) = result {
        println!("{text}");
    }

    Ok(())
}