Add a couple verbs and use tabwriter output.

This commit is contained in:
Bill Thiede 2019-11-18 21:25:23 -08:00
parent 13cc1b6d0d
commit d2866bace7
4 changed files with 59 additions and 2 deletions

10
Cargo.lock generated
View File

@ -454,6 +454,7 @@ dependencies = [
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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]] [[package]]
@ -477,6 +478,14 @@ dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "termcolor" name = "termcolor"
version = "0.3.6" 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 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 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 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 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 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" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"

View File

@ -10,6 +10,7 @@ edition = "2018"
failure = "0.1" failure = "0.1"
glob = "0.3" glob = "0.3"
human_format = { git ="https://github.com/wathiede/human-format-rs" } human_format = { git ="https://github.com/wathiede/human-format-rs" }
humantime = "1"
lazy_static = "1.4" lazy_static = "1.4"
log = "0.4" log = "0.4"
rayon = "1.2" rayon = "1.2"
@ -18,4 +19,4 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1" serde_json = "1"
stderrlog = "0.4" stderrlog = "0.4"
structopt = "0.3" structopt = "0.3"
humantime = "1" tabwriter = "1"

View File

@ -178,7 +178,7 @@ pub struct SubtitleFormat {
#[derive(Clone, Deserialize, Debug, Serialize)] #[derive(Clone, Deserialize, Debug, Serialize)]
pub struct CompactMetadata { pub struct CompactMetadata {
bit_rate: usize, pub bit_rate: usize,
pub duration: f32, pub duration: f32,
filename: String, filename: String,
format_name: String, format_name: String,

View File

@ -1,5 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error; use std::error::Error;
use std::io::Write;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::time::Duration; use std::time::Duration;
@ -10,6 +11,7 @@ use humantime;
use log::info; use log::info;
use regex::Regex; use regex::Regex;
use structopt::StructOpt; use structopt::StructOpt;
use tabwriter::TabWriter;
use superdeduper::CompactMetadata; use superdeduper::CompactMetadata;
use superdeduper::MovieLibrary; use superdeduper::MovieLibrary;
@ -27,6 +29,34 @@ fn clean_path_parent<P: AsRef<Path>>(path: P) -> PathBuf {
PathBuf::from(path) PathBuf::from(path)
} }
fn print_dupes(videos: HashMap<String, CompactMetadata>) {}
fn print_all(videos: HashMap<String, CompactMetadata>) {
let mut names = videos.keys().collect::<Vec<_>>();
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<PathBuf, Vec<(String, CompactMetadata)>>) { fn print_video_groups(video_groups: &HashMap<PathBuf, Vec<(String, CompactMetadata)>>) {
let mut names = video_groups.keys().collect::<Vec<_>>(); let mut names = video_groups.keys().collect::<Vec<_>>();
names.sort(); names.sort();
@ -89,6 +119,10 @@ enum Command {
about = "Read full metadata file and write compact file." about = "Read full metadata file and write compact file."
)] )]
CompactMetadata, 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")] #[structopt(name = "update-metadata", about = "Write full metadata files")]
UpdateMetadata, UpdateMetadata,
#[structopt( #[structopt(
@ -154,6 +188,18 @@ fn main() -> Result<(), Box<dyn Error>> {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(MOVIE_DIR);
lib.compact_metadata()?; 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 => { Command::UpdateMetadata => {
let lib = MovieLibrary::new(MOVIE_DIR); let lib = MovieLibrary::new(MOVIE_DIR);
lib.update_metadata()?; lib.update_metadata()?;