instead of sorting just find max width height format
This commit is contained in:
parent
1cef56d964
commit
9048693a15
2 changed files with 9 additions and 8 deletions
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue