diff --git a/Cargo.lock b/Cargo.lock index aeed37f..139d04b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + [[package]] name = "block-buffer" version = "0.12.1" @@ -11,6 +17,12 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "cfg-if" version = "1.0.4" @@ -32,6 +44,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8498c871161e1742aaa9d52551b2d6ebdd4c3d45a3be423e3728f33b955be550" +dependencies = [ + "cfg-if", +] + [[package]] name = "crypto-common" version = "0.2.2" @@ -41,6 +62,12 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "data-encoding" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06" + [[package]] name = "digest" version = "0.11.3" @@ -52,6 +79,16 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "hex" version = "0.4.3" @@ -73,6 +110,81 @@ version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" +[[package]] +name = "lofty" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0f052e8f93a76f4b2cd551c38a77d3025c7be1dc473f7acbac0ef1663c9f33b" +dependencies = [ + "byteorder", + "data-encoding", + "flate2", + "lofty_attr", + "log", + "ogg_pager", + "paste", +] + +[[package]] +name = "lofty_attr" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdbca1b60ba7cea959ffc84ac27f3dbdbacd6dfda168c7eabbc00e48654bb9fd" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "ogg_pager" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d36b1d6964c3ac92b7aea701057e02b6b91143d70d83b20abf75a231a3c0216" +dependencies = [ + "byteorder", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + [[package]] name = "sha2" version = "0.11.0" @@ -84,11 +196,29 @@ dependencies = [ "digest", ] +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "syn" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "timbre" version = "0.1.0" dependencies = [ "hex", + "lofty", "sha2", ] @@ -97,3 +227,9 @@ name = "typenum" version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" diff --git a/Cargo.toml b/Cargo.toml index c963ec9..45558ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ edition = "2024" [dependencies] hex = "0.4.3" +lofty = "0.25.1" sha2 = "0.11.0" diff --git a/src/main.rs b/src/main.rs index e802104..e9a0bf3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,15 @@ -use core::panic; use sha2::{Digest, Sha256}; use std::{ - fs::{File, create_dir_all}, + fs::{self, File, create_dir_all}, io::{BufReader, Read}, + path::{Path, PathBuf}, }; #[cfg(not(target_os = "linux"))] compile_error!("kitty like linux more"); -fn hashcat() { - let file = File::open("cat_01.jpg").expect("how dare u! i want my cat back :("); +fn hashcat(cat_path: &Path) { + let file = File::open(cat_path).expect("how dare u! i want my cat back :("); let mut cat = BufReader::new(file); let mut hasher = Sha256::new(); @@ -32,11 +32,56 @@ fn hashcat() { } } +fn is_audio(path: &Path) -> bool { + match path.extension().and_then(|e| e.to_str()) { + Some(ext) => { + if matches!( + ext.to_lowercase().as_str(), + "flac" | "mp3" | "m4a" | "ogg" | "opus" | "wav" + ) { + true + } else { + println!( + "while looking through each of your songs, i found one that i don't understand.\nits named {}, and i don't understand it's file extension.\nyou can try to help teach me by opening a git issue if it's a music file! :)\ni will continue, but ignore this file :(", + path.display() + ); + false + } + } + None => false, + } +} +fn scan(dir: &Path, out: &mut Vec) { + for entry in fs::read_dir(dir) + .expect("i want to help you, but i don't know how to read your music folder :( sorry.") + { + let path=entry.expect( + "i wanna help you, but, i can't do everything. i couldn't read a file, to the point where i can't tell you which :(").path(); + if path.is_dir() { + scan(&path, out); + } else if is_audio(&path) { + out.push(path); + } + } +} + fn main() { - hashcat(); // meow - let timbre_dir = std::env::home_dir() - .expect("NERD!!!") + let cat = include_bytes!("../cat_01.jpg"); // my kitty! + + let timbre_dir = Path::new(&std::env::var("HOME").expect("NERD!!!")) .join("Music") .join("Timbre"); - create_dir_all(timbre_dir).expect("wat"); + + if !timbre_dir.exists() { + println!("First run detected... Initializing..."); + create_dir_all(&timbre_dir).expect("wat"); + fs::write(timbre_dir.join("cat_01.jpg"), cat) + .expect("my cat! he can't come! what did you do!?!"); + println!("Done!"); + } else { + hashcat(&timbre_dir.join("cat_01.jpg")); // meow + } + let mut tracks = Vec::new(); + scan(&timbre_dir.join("Tracks"), &mut tracks); + println!("Found {} audio files", tracks.len()); }