static regular expressions; if filename contains both episode number and year, favour episode over movie; print out some help text about videos
This commit is contained in:
39
src/main.rs
39
src/main.rs
@@ -2,6 +2,7 @@ use std::fs::DirEntry;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
|
||||
fn home_dir() -> PathBuf {
|
||||
@@ -101,23 +102,41 @@ fn handle_mp3(file: DirEntry) {
|
||||
}
|
||||
}
|
||||
|
||||
/// if filename contains something like `(1971)` or `[2003]` it's a movie
|
||||
fn is_movie(file: &DirEntry) -> bool {
|
||||
lazy_static! {
|
||||
static ref MOVIE: Regex = Regex::new(r"\(\d{4}\)|\[\d{4}]").unwrap();
|
||||
}
|
||||
|
||||
MOVIE.is_match(file.file_name().to_str().unwrap())
|
||||
}
|
||||
|
||||
/// if filename contains something like "S03E21" it's a TV programme
|
||||
fn is_tv_episode(file: &DirEntry) -> bool {
|
||||
lazy_static! {
|
||||
static ref TV: Regex = Regex::new(r"s\d{2}e\d{2}").unwrap();
|
||||
}
|
||||
|
||||
TV.is_match(file.file_name().to_str().unwrap())
|
||||
}
|
||||
|
||||
fn handle_video(file: DirEntry) {
|
||||
let mut destination = vec!["Videos"];
|
||||
|
||||
// if filename contains something like "(1971)" or "[2003]" it's a movie
|
||||
// if filename contains something like "S03E21" it's a TV programme
|
||||
|
||||
let movie = Regex::new(r"\(\d{4}\)|\[\d{4}]").unwrap();
|
||||
let tv = Regex::new(r"s\d{2}e\d{2}").unwrap();
|
||||
|
||||
if movie.is_match(file.file_name().to_str().unwrap()) {
|
||||
if is_tv_episode(&file) {
|
||||
destination.push("TV");
|
||||
} else if is_movie(&file) {
|
||||
// todo match decade?
|
||||
destination.push("Movies");
|
||||
} else if tv.is_match(file.file_name().to_str().unwrap()) {
|
||||
destination.push("TV");
|
||||
}
|
||||
|
||||
move_file(file.path(), create_dir_if_not_exists(destination));
|
||||
println!(
|
||||
"Move to ~/{}/{}?", destination.join("/"), file.file_name().to_str().unwrap()
|
||||
);
|
||||
|
||||
if yes() {
|
||||
move_file(file.path(), create_dir_if_not_exists(destination));
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_dir(path: PathBuf) {
|
||||
|
||||
Reference in New Issue
Block a user