implement pretty output for YtDlpFormat

This commit is contained in:
mykola2312 2024-02-19 14:50:44 +02:00
parent 5dace36e03
commit 402e2ca990
2 changed files with 31 additions and 1 deletions

View file

@ -28,6 +28,34 @@ impl YtDlpFormat {
self.vcodec = None self.vcodec = None
} }
} }
fn str_option<T>(opt: &Option<T>) -> String
where
T: ToString,
{
if let Some(value) = opt {
value.to_string()
} else {
"None".to_string()
}
}
}
impl fmt::Display for YtDlpFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"id\t{}\text\t{}\tw\t{}\th\t{}\tvcodec\t{}\tvbr\t{}\tacodec\t{}\tabr\t{}",
self.format_id,
self.ext,
Self::str_option(&self.width),
Self::str_option(&self.height),
Self::str_option(&self.vcodec),
Self::str_option(&self.vbr),
Self::str_option(&self.acodec),
Self::str_option(&self.abr)
)
}
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]

View file

@ -39,7 +39,9 @@ async fn main() -> anyhow::Result<()> {
let info = YtDlp::load_info(env::var("TEST_URL")?.as_str()) let info = YtDlp::load_info(env::var("TEST_URL")?.as_str())
.await .await
.expect("load_info"); .expect("load_info");
dbg!(info); for format in info.formats {
println!("{}", format);
}
Ok(()) Ok(())
//bot_main().await //bot_main().await