Compare commits

...

3 Commits

3 changed files with 16 additions and 30 deletions

1
.envrc
View File

@ -1 +0,0 @@
use_nix

View File

@ -1,27 +0,0 @@
let
pkgs = import <nixpkgs> {
overlays = [
(import (builtins.fetchTarball
"https://github.com/oxalica/rust-overlay/archive/master.tar.gz"))
];
};
rust = pkgs.rust-bin.stable.latest.rust.override {
extensions = [ "rust-src" ];
};
in with pkgs;
pkgs.mkShell rec {
name = "rust";
buildInputs = [
openssl
pkg-config
cargo
rust
rustfmt
rust-analyzer
wasm-pack
wasm-bindgen-cli
nodePackages.rollup
];
}

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
@ -367,6 +379,8 @@ impl Movies {
let parent = clean_path_parent(path) let parent = clean_path_parent(path)
.to_string_lossy() .to_string_lossy()
.to_ascii_lowercase() .to_ascii_lowercase()
.replace("-", " ")
.replace("'", "")
.to_string(); .to_string();
if date_re.is_match(&parent) { if date_re.is_match(&parent) {
movie_counter.entry(parent).or_insert(Vec::new()).push(m); movie_counter.entry(parent).or_insert(Vec::new()).push(m);
@ -388,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.