Initial commit.
This commit is contained in:
59
src/main.rs
Normal file
59
src/main.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
extern crate mime;
|
||||
extern crate mime_guess;
|
||||
extern crate structopt;
|
||||
#[macro_use]
|
||||
extern crate structopt_derive;
|
||||
extern crate unrar;
|
||||
extern crate walkdir;
|
||||
|
||||
use mime_guess::guess_mime_type;
|
||||
use unrar::archive;
|
||||
use structopt::StructOpt;
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "megaunpack")]
|
||||
struct Opt {
|
||||
#[structopt(short = "q", long = "quiet")]
|
||||
quiet: bool,
|
||||
#[structopt(short = "v", long = "verbose")]
|
||||
verbose: u64,
|
||||
path: String
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_file(entry: &DirEntry) -> bool {
|
||||
entry.file_type().is_file()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_archive(entry: &DirEntry) -> bool {
|
||||
match entry.path().to_str() {
|
||||
Some(path) => archive::is_archive(path),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_video(entry: &DirEntry) -> bool {
|
||||
let mime = guess_mime_type(entry.path());
|
||||
|
||||
match mime.type_() {
|
||||
mime::VIDEO => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
let entries = WalkDir::new(&opt.path)
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
.filter(is_file)
|
||||
.filter(is_archive);
|
||||
|
||||
for entry in entries {
|
||||
println!("{:?}", entry);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user