70 lines
1.4 KiB
Rust
70 lines
1.4 KiB
Rust
extern crate mime;
|
|
extern crate mime_guess;
|
|
extern crate structopt;
|
|
#[macro_use]
|
|
extern crate structopt_derive;
|
|
extern crate unrar;
|
|
extern crate walkdir;
|
|
|
|
use std::collections::HashSet;
|
|
|
|
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);
|
|
|
|
let mut archives = HashSet::new();
|
|
|
|
for entry in entries {
|
|
if let Some(path) = entry.path().to_str() {
|
|
let mut archive = archive::Archive::new(String::from(path));
|
|
|
|
archives.insert(archive.first_part());
|
|
}
|
|
}
|
|
|
|
println!("{:#?}", archives);
|
|
}
|