From 4b1cf6c491b62884a24f82999259d70c79150891 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sat, 25 Dec 2021 09:30:55 -0800 Subject: [PATCH] Fix movie size comparison. Use largest movie pixel size (some movies have low res video streams embedded). --- src/lib.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bc46c89..649d462 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -320,6 +320,18 @@ pub struct Movie { } impl Movie { + fn max_pixel_count(&self) -> Option { + if self.files.is_empty() { + None + } else { + Some(self.files.iter().fold(usize::min_value(), |acc, (_, cmd)| { + let min = cmd.video.iter().fold(usize::min_value(), |acc, v| { + std::cmp::max(acc, v.width * v.height) + }); + std::cmp::max(acc, min) + })) + } + } fn min_pixel_count(&self) -> Option { if self.files.is_empty() { None @@ -366,7 +378,7 @@ pub struct Movies { impl Movies { /// Find all movies with multiple copies. The returned vec contains a tuple of (Movie to keep, - /// One or more Movies to remove). The highest bit rate movie is kept. + /// One or more Movies to remove). The highest resolution movie is kept. /// Movies with differing years are considered distinct movies. /// If there is a yearless movie and one or more movies with a year exist, then the yearless /// movie will be removed @@ -409,8 +421,9 @@ impl Movies { for (_parent, mut movies) in movie_counter.into_iter() { if movies.len() > 1 { + dbg!(&movies); // Sort, lowest resolution movie first - movies.sort_by(|a, b| a.min_pixel_count().cmp(&b.min_pixel_count())); + movies.sort_by(|a, b| a.max_pixel_count().cmp(&b.max_pixel_count())); // Flip order, we care about the largest. movies.reverse(); // Take the largest image, return the rest for removal.