handle tv/movies a bit better

This commit is contained in:
2022-11-06 23:06:25 +00:00
parent 6e9e8df3bf
commit 12ddfd2b8c
3 changed files with 57 additions and 4 deletions

View File

@@ -2,6 +2,8 @@ use std::fs::DirEntry;
use std::io;
use std::path::PathBuf;
use regex::Regex;
fn home_dir() -> PathBuf {
dirs::home_dir().expect("Couldn't find home dir")
}
@@ -100,9 +102,22 @@ fn handle_mp3(file: DirEntry) {
}
fn handle_video(file: DirEntry) {
// todo if filename contains something like "(1971)" or "[2003]" it's a movie
// todo if filename contains something like "S03E21" it's a TV programme
move_file(file.path(), create_dir_if_not_exists(vec!["Videos"]));
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()) {
// 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));
}
fn handle_dir(path: PathBuf) {
@@ -123,8 +138,12 @@ fn handle_dir(path: PathBuf) {
"jpeg" => { handle_image(inode) }
"png" => { handle_image(inode) }
"mp3" => { handle_mp3( inode) }
"mp4" => { handle_video( inode) }
"avi" => { handle_video(inode) }
"m4v" => { handle_video(inode) }
"mkv" => { handle_video(inode) }
"mp4" => { handle_video(inode) }
// todo m4a, flac, etc?
// todo pdf, other documents
_ => { /*println!("Here's where we would do nothing.");*/ }
}
}