scanning for songs

This commit is contained in:
2026-08-22 21:05:57 -04:00
parent 2c6615ea48
commit d510379788
3 changed files with 190 additions and 8 deletions

View File

@@ -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<PathBuf>) {
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());
}