use std::time::Duration;
use unbundle::{MediaFile, UnbundleError};
fn main() -> Result<(), UnbundleError> {
let path = std::env::args()
.nth(1)
.expect("Usage: subtitle_search <video_path>");
let mut unbundler = MediaFile::open(&path)?;
let meta = unbundler.metadata();
if let Some(tags) = &meta.tags {
println!("Container tags:");
for (key, value) in tags {
println!(" {key}: {value}");
}
} else {
println!("No container tags found.");
}
if let Some(video) = &meta.video {
println!("\nColorspace info:");
println!(" Color space: {:?}", video.color_space);
println!(" Color range: {:?}", video.color_range);
println!(" Color primaries: {:?}", video.color_primaries);
println!(" Color transfer: {:?}", video.color_transfer);
println!(" Bits per raw sample: {:?}", video.bits_per_raw_sample);
println!(" Pixel format: {:?}", video.pixel_format_name);
}
if meta.subtitle.is_some() {
println!("\nSearching subtitles for 'hello'...");
let results = unbundler.subtitle().search("hello")?;
if results.is_empty() {
println!(" No matches found.");
} else {
for event in &results {
println!(
" [{:?} – {:?}] {}",
event.start_time, event.end_time, event.text
);
}
}
println!("\nSubtitles in first 3 seconds:");
let range = unbundler
.subtitle()
.extract_range(Duration::ZERO, Duration::from_secs(3))?;
for event in &range {
println!(
" [{:?} – {:?}] {}",
event.start_time, event.end_time, event.text
);
}
} else {
println!("\nNo subtitle stream found.");
}
Ok(())
}