diff --git a/Cargo.lock b/Cargo.lock index abf98a0..35b0e59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -454,6 +454,7 @@ dependencies = [ "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "stderrlog 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tabwriter 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -477,6 +478,14 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tabwriter" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "termcolor" version = "0.3.6" @@ -617,6 +626,7 @@ dependencies = [ "checksum structopt-derive 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8fe0c13e476b4e21ff7f5c4ace3818b6d7bdc16897c31c73862471bc1663acae" "checksum syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7bedb3320d0f3035594b0b723c8a28d7d336a3eda3881db79e61d676fb644c" "checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203" +"checksum tabwriter 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9128e3a9149e51494cad59712a286e149fcb74e443d2298d69bd6eaa42cc4ebb" "checksum termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" diff --git a/Cargo.toml b/Cargo.toml index 4790170..717fdae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" failure = "0.1" glob = "0.3" human_format = { git ="https://github.com/wathiede/human-format-rs" } +humantime = "1" lazy_static = "1.4" log = "0.4" rayon = "1.2" @@ -18,4 +19,4 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1" stderrlog = "0.4" structopt = "0.3" -humantime = "1" +tabwriter = "1" diff --git a/src/lib.rs b/src/lib.rs index 94fa63d..29e734c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -178,7 +178,7 @@ pub struct SubtitleFormat { #[derive(Clone, Deserialize, Debug, Serialize)] pub struct CompactMetadata { - bit_rate: usize, + pub bit_rate: usize, pub duration: f32, filename: String, format_name: String, diff --git a/src/main.rs b/src/main.rs index 3d140b3..0244567 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::error::Error; +use std::io::Write; use std::path::Path; use std::path::PathBuf; use std::time::Duration; @@ -10,6 +11,7 @@ use humantime; use log::info; use regex::Regex; use structopt::StructOpt; +use tabwriter::TabWriter; use superdeduper::CompactMetadata; use superdeduper::MovieLibrary; @@ -27,6 +29,34 @@ fn clean_path_parent>(path: P) -> PathBuf { PathBuf::from(path) } +fn print_dupes(videos: HashMap) {} + +fn print_all(videos: HashMap) { + let mut names = videos.keys().collect::>(); + names.sort(); + + let mut fmtr = Formatter::new(); + fmtr.with_separator(""); + fmtr.with_scales(Scales::Binary()); + let mut tw = TabWriter::new(vec![]); + for name in names { + let clean_name = clean_path_parent(&name); + let md = &videos[name]; + write!( + &mut tw, + "{}B/s\t{}\t{}\t{}\t{}\n", + fmtr.format(md.bit_rate as f64), + md.largest_dimension().unwrap(), + fmtr.format(md.size as f64), + humantime::Duration::from(Duration::from_secs(md.duration as u64)), + name, + ) + .unwrap(); + //&p[p.rfind("/").unwrap() + 1..] + } + println!("{}", String::from_utf8(tw.into_inner().unwrap()).unwrap()); +} + fn print_video_groups(video_groups: &HashMap>) { let mut names = video_groups.keys().collect::>(); names.sort(); @@ -89,6 +119,10 @@ enum Command { about = "Read full metadata file and write compact file." )] CompactMetadata, + #[structopt(name = "print-all", about = "Print useful metadata about all files")] + PrintAll, + #[structopt(name = "print-dupes", about = "Print duplicate movies")] + PrintDupes, #[structopt(name = "update-metadata", about = "Write full metadata files")] UpdateMetadata, #[structopt( @@ -154,6 +188,18 @@ fn main() -> Result<(), Box> { let lib = MovieLibrary::new(MOVIE_DIR); lib.compact_metadata()?; } + Command::PrintDupes => { + let lib = MovieLibrary::new(MOVIE_DIR); + let videos = lib.videos(false)?; + + print_dupes(videos); + } + Command::PrintAll => { + let lib = MovieLibrary::new(MOVIE_DIR); + let videos = lib.videos(false)?; + + print_all(videos); + } Command::UpdateMetadata => { let lib = MovieLibrary::new(MOVIE_DIR); lib.update_metadata()?;