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

View file

@ -39,9 +39,11 @@ 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");
// for format in info.formats { for format in &info.formats {
// println!("{}", format); println!("{}", format);
// } }
println!("");
let video = info.best_video_format().unwrap(); let video = info.best_video_format().unwrap();
println!("{}", video); println!("{}", video);