Compare commits
2 Commits
ef110fcb94
...
825482ba07
Author | SHA1 | Date |
---|---|---|
Max Bradbury | 825482ba07 | |
Max Bradbury | 3c471c46b0 |
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "download-organiser"
|
name = "download-organiser"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -9,6 +9,10 @@ fn home_dir() -> PathBuf {
|
||||||
dirs::home_dir().expect("Couldn't find home dir")
|
dirs::home_dir().expect("Couldn't find home dir")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn documents_dir() -> PathBuf {
|
||||||
|
dirs::document_dir().expect("Couldn't find downloads dir")
|
||||||
|
}
|
||||||
|
|
||||||
fn downloads_dir() -> PathBuf {
|
fn downloads_dir() -> PathBuf {
|
||||||
dirs::download_dir().expect("Couldn't find downloads dir")
|
dirs::download_dir().expect("Couldn't find downloads dir")
|
||||||
}
|
}
|
||||||
|
@ -102,10 +106,18 @@ fn handle_mp3(file: DirEntry) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// if filename contains something like `(1971)` or `[2003]` it's a movie
|
fn handle_pdf(file: DirEntry) {
|
||||||
|
let mut dir = documents_dir();
|
||||||
|
|
||||||
|
dir.push("PDFs");
|
||||||
|
|
||||||
|
move_file(file.path(), dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// if filename contains something like `(1971)` or `[2003]` or `.1985.` it's a movie
|
||||||
fn is_movie(file: &DirEntry) -> bool {
|
fn is_movie(file: &DirEntry) -> bool {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref MOVIE: Regex = Regex::new(r"\(\d{4}\)|\[\d{4}]").unwrap();
|
static ref MOVIE: Regex = Regex::new(r"\.\d{4}\.|\(\d{4}\)|\[\d{4}]").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
MOVIE.is_match(file.file_name().to_str().unwrap())
|
MOVIE.is_match(file.file_name().to_str().unwrap())
|
||||||
|
@ -114,7 +126,7 @@ fn is_movie(file: &DirEntry) -> bool {
|
||||||
/// if filename contains something like "S03E21" it's a TV programme
|
/// if filename contains something like "S03E21" it's a TV programme
|
||||||
fn is_tv_episode(file: &DirEntry) -> bool {
|
fn is_tv_episode(file: &DirEntry) -> bool {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref TV: Regex = Regex::new(r"s\d{2}\s*e\d{2}").unwrap();
|
static ref TV: Regex = Regex::new(r"[sS]\d{2}\s*[eE][pP]?\d{2}").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
TV.is_match(file.file_name().to_str().unwrap())
|
TV.is_match(file.file_name().to_str().unwrap())
|
||||||
|
@ -142,6 +154,8 @@ fn handle_video(file: DirEntry) {
|
||||||
fn handle_dir(path: PathBuf) {
|
fn handle_dir(path: PathBuf) {
|
||||||
let dir = std::fs::read_dir(path).expect("Couldn't read dir");
|
let dir = std::fs::read_dir(path).expect("Couldn't read dir");
|
||||||
|
|
||||||
|
// todo if dir is empty, delete
|
||||||
|
|
||||||
for inode in dir {
|
for inode in dir {
|
||||||
let inode = inode.expect("Couldn't read inode");
|
let inode = inode.expect("Couldn't read inode");
|
||||||
|
|
||||||
|
@ -157,6 +171,7 @@ fn handle_dir(path: PathBuf) {
|
||||||
"jpeg" => { handle_image(inode) }
|
"jpeg" => { handle_image(inode) }
|
||||||
"png" => { handle_image(inode) }
|
"png" => { handle_image(inode) }
|
||||||
"mp3" => { handle_mp3( inode) }
|
"mp3" => { handle_mp3( inode) }
|
||||||
|
"pdf" => { handle_pdf( inode) }
|
||||||
"avi" => { handle_video(inode) }
|
"avi" => { handle_video(inode) }
|
||||||
"m4v" => { handle_video(inode) }
|
"m4v" => { handle_video(inode) }
|
||||||
"mkv" => { handle_video(inode) }
|
"mkv" => { handle_video(inode) }
|
||||||
|
|
Loading…
Reference in New Issue