instead of sorting just find max width height format

This commit is contained in:
mykola2312 2024-02-20 16:06:58 +02:00
parent d1bced33b5
commit 6602016d44
2 changed files with 9 additions and 8 deletions

View file

@ -83,7 +83,7 @@ impl YtDlpInfo {
}
pub fn best_video_format(&self) -> Option<&YtDlpFormat> {
let mut formats: Vec<VideoFormat> = self
let format = self
.formats
.iter()
.filter_map(|f| {
@ -97,10 +97,9 @@ impl YtDlpInfo {
None
}
})
.collect();
formats.sort_unstable_by_key(|f| (f.width, f.height));
.max_by_key(|f| (f.width, f.height));
match formats.last() {
match format {
Some(vf) => Some(vf.format),
None => None,
}

View file

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