diff --git a/src/dl/yt_dlp.rs b/src/dl/yt_dlp.rs index 7c824cc..007e48e 100644 --- a/src/dl/yt_dlp.rs +++ b/src/dl/yt_dlp.rs @@ -83,7 +83,7 @@ impl YtDlpInfo { } pub fn best_video_format(&self) -> Option<&YtDlpFormat> { - let mut formats: Vec = 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)); - - match formats.last() { + .max_by_key(|f| (f.width, f.height)); + + match format { Some(vf) => Some(vf.format), None => None, } diff --git a/src/main.rs b/src/main.rs index 598e2cd..ec60042 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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);