image handling

This commit is contained in:
Max Bradbury 2021-11-26 00:35:24 +00:00
parent 3b9789235d
commit 8d584d2af1
1 changed files with 23 additions and 6 deletions

View File

@ -7,7 +7,11 @@ fn home_dir() -> PathBuf {
}
fn downloads_dir() -> PathBuf {
dirs::download_dir().expect("Couldn't find download dir")
dirs::download_dir().expect("Couldn't find downloads dir")
}
fn pictures_dir() -> PathBuf {
dirs::picture_dir().expect("Couldn't find pictures dir")
}
fn strip_null_bytes(str: &str) -> String {
@ -46,6 +50,19 @@ fn yes() -> bool {
answer.to_lowercase().starts_with("y")
}
fn handle_image(file: DirEntry) {
move_file(file.path(), pictures_dir());
}
fn handle_gif(file: DirEntry) {
let mut dir = pictures_dir();
dir.push("Internet");
dir.push("GIFs");
move_file(file.path(), dir);
}
fn handle_mp3(file: DirEntry) {
let meta = mp3_metadata::read_from_file(file.path()).unwrap();
@ -85,11 +102,11 @@ fn handle_dir(path: PathBuf) {
}
match inode.path().extension().unwrap_or("none".as_ref()).to_str() {
Some("gif") => { /*println!("Here's where we would move things to ~/Pictures");*/ }
Some("jpg") => { /*println!("Here's where we would move things to ~/Pictures");*/ }
Some("jpeg") => { /*println!("Here's where we would move things to ~/Pictures");*/ }
Some("png") => { /*println!("Here's where we would move things to ~/Pictures");*/ }
Some("mp3") => { handle_mp3(inode) }
Some("gif") => { handle_gif( inode) }
Some("jpg") => { handle_image(inode) }
Some("jpeg") => { handle_image(inode) }
Some("png") => { handle_image(inode) }
Some("mp3") => { handle_mp3( inode) }
// todo m4a, flac, etc?
_ => { /*println!("Here's where we would do nothing.");*/ }
}