diff --git a/src/bot/bot.rs b/src/bot/bot.rs index 12c8ba0..06f44af 100644 --- a/src/bot/bot.rs +++ b/src/bot/bot.rs @@ -140,12 +140,14 @@ enum Command { use crate::dl::ffprobe::FFProbe; async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult { - if let Ok(probe) = FFProbe::probe("/home/mykola/Videos/test-video").await { - if let Some(vs) = probe.get_video_stream() { - dbg!(vs.get_video_resolution()); + if cfg!(debug_assertions) { + if let Ok(probe) = FFProbe::probe("/home/mykola/Videos/test-video").await { + if let Some(vs) = probe.get_video_stream() { + dbg!(vs.get_video_resolution()); + } + } else { + dbg!("failed"); } - } else { - dbg!("failed"); } Ok(()) diff --git a/src/bot/dl.rs b/src/bot/dl.rs index 649548d..9ae5640 100644 --- a/src/bot/dl.rs +++ b/src/bot/dl.rs @@ -17,13 +17,19 @@ async fn bot_download(bot: Bot, msg: Message, url: String) -> HandlerResult { } }; - // query media info with - // ffprobe -v quiet -print_format json -show_streams -select_streams v:0 input.mp4 - let probe = FFProbe::probe(&output.path).await; - dbg!(probe); - let mut video = bot.send_video(msg.chat.id, InputFile::file(&output.path)); - // set width, height and so on + // try getting video resolution + if let Ok(probe) = FFProbe::probe(&output.path).await { + if let Some(vs) = probe.get_video_stream() { + if let Some((width, height)) = vs.get_video_resolution() { + video.width = Some(width); + video.height = Some(height); + } + + // set video duration + video.duration = Some(vs.duration as u32); + } + } video.await?;