fix json parsing error
This commit is contained in:
parent
cccff3edc2
commit
2e6edffcb7
3 changed files with 26 additions and 13 deletions
|
|
@ -137,14 +137,10 @@ enum Command {
|
||||||
DeclineChat(String),
|
DeclineChat(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::dl::spawn::spawn;
|
use crate::dl::ffprobe::FFProbe;
|
||||||
|
|
||||||
async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
|
async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
|
||||||
//bot.send_message(msg.chat.id, t!("test_response")).await?;
|
dbg!(FFProbe::probe("/home/mykola/Videos/test-video").await);
|
||||||
let output = spawn("python", &["-c", "import os; print(os.environ)"])
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
println!("{}", std::str::from_utf8(&output.stdout[0..4095]).unwrap());
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ use tracing::{event, Level};
|
||||||
use super::types::HandlerResult;
|
use super::types::HandlerResult;
|
||||||
use crate::dl::download;
|
use crate::dl::download;
|
||||||
|
|
||||||
|
use crate::dl::ffprobe::FFProbe;
|
||||||
|
|
||||||
async fn bot_download(bot: Bot, msg: Message, url: String) -> HandlerResult {
|
async fn bot_download(bot: Bot, msg: Message, url: String) -> HandlerResult {
|
||||||
let output = match download(url.as_str()).await {
|
let output = match download(url.as_str()).await {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
|
|
@ -17,6 +19,8 @@ async fn bot_download(bot: Bot, msg: Message, url: String) -> HandlerResult {
|
||||||
|
|
||||||
// query media info with
|
// query media info with
|
||||||
// ffprobe -v quiet -print_format json -show_streams -select_streams v:0 input.mp4
|
// 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));
|
let mut video = bot.send_video(msg.chat.id, InputFile::file(&output.path));
|
||||||
// set width, height and so on
|
// set width, height and so on
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,27 @@
|
||||||
use super::spawn::{spawn, SpawnError};
|
use super::spawn::{spawn, SpawnError};
|
||||||
use serde::Deserialize;
|
use serde::{de, de::Error, Deserialize, Deserializer};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
fn duration_from_str<'de, D>(deserializer: D) -> Result<f64, D::Error>
|
||||||
|
where D: Deserializer<'de>
|
||||||
|
{
|
||||||
|
let s = String::deserialize(deserializer)?;
|
||||||
|
|
||||||
|
Ok(str::parse(&s).map_err(de::Error::custom)?)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct FFProbeStream {
|
pub struct FFProbeStream {
|
||||||
pub index: u32,
|
pub index: u32,
|
||||||
pub codec_name: String,
|
pub codec_name: String,
|
||||||
pub width: u32,
|
pub width: Option<u32>,
|
||||||
pub height: u32,
|
pub height: Option<u32>,
|
||||||
pub coded_width: u32,
|
pub coded_width: Option<u32>,
|
||||||
pub coded_height: u32,
|
pub coded_height: Option<u32>,
|
||||||
pub time_base: String,
|
pub time_base: String,
|
||||||
pub duration_ts: u64,
|
pub duration_ts: u64,
|
||||||
|
|
||||||
|
#[serde(deserialize_with = "duration_from_str")]
|
||||||
pub duration: f64
|
pub duration: f64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,12 +32,15 @@ pub struct FFProbeOutput {
|
||||||
|
|
||||||
impl FFProbeOutput {
|
impl FFProbeOutput {
|
||||||
pub fn parse(json: &[u8]) -> Result<FFProbeOutput, serde_json::Error> {
|
pub fn parse(json: &[u8]) -> Result<FFProbeOutput, serde_json::Error> {
|
||||||
let output: FFProbeOutput = serde_json::from_slice(json)?;
|
let output: Result<FFProbeOutput, _> = serde_json::from_slice(json);
|
||||||
|
dbg!(output);
|
||||||
|
|
||||||
Ok(output)
|
todo!();
|
||||||
|
//Ok(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum FFProbeError {
|
pub enum FFProbeError {
|
||||||
SpawnError(SpawnError),
|
SpawnError(SpawnError),
|
||||||
JsonError
|
JsonError
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue