Prefer higher resolution files.

This commit is contained in:
Bill Thiede 2021-11-12 19:20:42 -08:00
parent 708e44053e
commit b2ef1d3d3d

View File

@ -320,6 +320,18 @@ pub struct Movie {
} }
impl Movie { impl Movie {
fn min_pixel_count(&self) -> Option<usize> {
if self.files.is_empty() {
None
} else {
Some(self.files.iter().fold(usize::max_value(), |acc, (_, cmd)| {
let min = cmd.video.iter().fold(usize::max_value(), |acc, v| {
std::cmp::min(acc, v.width * v.height)
});
std::cmp::min(acc, min)
}))
}
}
fn min_bit_rate(&self) -> Option<usize> { fn min_bit_rate(&self) -> Option<usize> {
if self.files.is_empty() { if self.files.is_empty() {
None None
@ -390,8 +402,8 @@ impl Movies {
for (_parent, mut movies) in movie_counter.into_iter() { for (_parent, mut movies) in movie_counter.into_iter() {
if movies.len() > 1 { if movies.len() > 1 {
// Sort, lowest bit_rate movie first // Sort, lowest resolution movie first
movies.sort_by(|a, b| a.min_bit_rate().cmp(&b.min_bit_rate())); movies.sort_by(|a, b| a.min_pixel_count().cmp(&b.min_pixel_count()));
// Flip order, we care about the largest. // Flip order, we care about the largest.
movies.reverse(); movies.reverse();
// Take the largest image, return the rest for removal. // Take the largest image, return the rest for removal.