Fix movie size comparison.

Use largest movie pixel size (some movies have low res video streams
    embedded).
This commit is contained in:
Bill Thiede 2021-12-25 09:30:55 -08:00
parent 70174e9e49
commit 4b1cf6c491

View File

@ -320,6 +320,18 @@ pub struct Movie {
} }
impl Movie { impl Movie {
fn max_pixel_count(&self) -> Option<usize> {
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<usize> { fn min_pixel_count(&self) -> Option<usize> {
if self.files.is_empty() { if self.files.is_empty() {
None None
@ -366,7 +378,7 @@ pub struct Movies {
impl Movies { impl Movies {
/// Find all movies with multiple copies. The returned vec contains a tuple of (Movie to keep, /// 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. /// 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 /// If there is a yearless movie and one or more movies with a year exist, then the yearless
/// movie will be removed /// movie will be removed
@ -409,8 +421,9 @@ 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 {
dbg!(&movies);
// Sort, lowest resolution movie first // 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. // 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.