Fix movie size comparison.
Use largest movie pixel size (some movies have low res video streams
embedded).
This commit is contained in:
parent
70174e9e49
commit
4b1cf6c491
17
src/lib.rs
17
src/lib.rs
@ -320,6 +320,18 @@ pub struct 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> {
|
||||
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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user