Add a couple verbs and use tabwriter output.

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

View File

@@ -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,

View File

@@ -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<P: AsRef<Path>>(path: P) -> PathBuf {
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)>>) {
let mut names = video_groups.keys().collect::<Vec<_>>();
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<dyn Error>> {
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()?;