check exit status instead of stdout empty & stderr non-empty. also begin working on algorithm to determine best format
This commit is contained in:
parent
402e2ca990
commit
28799ca380
1 changed files with 19 additions and 11 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use std::str::Utf8Error;
|
use std::{process::ExitStatus, str::Utf8Error};
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
|
@ -12,10 +12,10 @@ pub struct YtDlpFormat {
|
||||||
pub width: Option<u16>,
|
pub width: Option<u16>,
|
||||||
pub height: Option<u16>,
|
pub height: Option<u16>,
|
||||||
pub ext: String,
|
pub ext: String,
|
||||||
pub acodec: Option<String>,
|
|
||||||
pub vcodec: Option<String>,
|
pub vcodec: Option<String>,
|
||||||
pub abr: Option<f32>,
|
pub acodec: Option<String>,
|
||||||
pub vbr: Option<f32>,
|
pub vbr: Option<f32>,
|
||||||
|
pub abr: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl YtDlpFormat {
|
impl YtDlpFormat {
|
||||||
|
|
@ -66,10 +66,21 @@ pub struct YtDlpInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl YtDlpInfo {
|
impl YtDlpInfo {
|
||||||
pub fn process(&mut self) {
|
pub fn parse(json: &[u8]) -> Result<YtDlpInfo, serde_json::Error> {
|
||||||
for format in &mut self.formats {
|
let mut info: YtDlpInfo = serde_json::from_slice(json)?;
|
||||||
|
for format in &mut info.formats {
|
||||||
format.process()
|
format.process()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(info)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn best_video_format(&self) -> Option<&str> {
|
||||||
|
//self.formats
|
||||||
|
// .iter()
|
||||||
|
|
||||||
|
|
||||||
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,14 +131,11 @@ impl YtDlp {
|
||||||
.output()
|
.output()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if output.stdout.is_empty() && !output.stderr.is_empty() {
|
if !output.status.success() {
|
||||||
let message = std::str::from_utf8(&output.stderr)?;
|
let message = std::str::from_utf8(&output.stderr)?;
|
||||||
return Err(YtDlpError::ErrorMessage(message.to_string()));
|
return Err(YtDlpError::ErrorMessage(message.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut info: YtDlpInfo = serde_json::from_slice(&output.stdout)?;
|
Ok(YtDlpInfo::parse(&output.stdout)?)
|
||||||
info.process();
|
|
||||||
|
|
||||||
Ok(info)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue