From 7277ca0cfa712e39ea24974d65232fa6bec41d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabor=20K=C3=B6rber?= Date: Sat, 20 Jan 2024 22:40:52 +0100 Subject: [PATCH] refactor: removing metadata package, and commented code; renaming template to soundboard.jinja --- Cargo.toml | 1 - src/main.rs | 2 +- src/soundclips.rs | 12 +----------- templates/{index.jinja => soundboard.jinja} | 0 4 files changed, 2 insertions(+), 13 deletions(-) rename templates/{index.jinja => soundboard.jinja} (100%) diff --git a/Cargo.toml b/Cargo.toml index 8e0d822..a981e77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ axum = "0.6.18" axum-template = { version = "0.19.0", features = ["minijinja"] } cpal = "0.15.2" log = "0.4.20" -# metadata = "0.1.8" minijinja = { version = "1.0.3", features = ["loader"] } minimp3 = "0.5.1" mp3-duration = "0.1.10" diff --git a/src/main.rs b/src/main.rs index f7161c1..bf53739 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ struct TemplateContext { async fn home(engine: TemplateEngine, state: State) -> impl axum::response::IntoResponse { let clips = state.0.clone().clips; // this is not ideal. let context = TemplateContext { clips: clips }; - RenderHtml(Key("index.jinja".to_owned()), engine, context) + RenderHtml(Key("soundboard.jinja".to_owned()), engine, context) } async fn play_handler( diff --git a/src/soundclips.rs b/src/soundclips.rs index 4023caa..93a2bcb 100644 --- a/src/soundclips.rs +++ b/src/soundclips.rs @@ -54,16 +54,6 @@ fn encode_filename(file_name: &str) -> String { hash_hex } -/* // needs metadata to install ffmpeg. -fn get_sound_clip_length(file_path: &str) -> Option { - if let Ok(meta) = metadata::media_file::MediaFileMetadata::new(&std::path::Path::new(file_path)) - { - return Some(meta._duration); - } - return None; -} -*/ - fn get_sound_clip_length(file_path: &str) -> Option { let path = std::path::Path::new(file_path); if let Ok(duration) = mp3_duration::from_path(&path) { @@ -77,6 +67,7 @@ fn get_sound_clip_length(file_path: &str) -> Option { fn normalize_filename(input: &str) -> String { // List of extensions to be removed + // TODO: this is hardcoded currently, add support to the provided list of extensions. let extensions = [".mp3", ".wav", ".flac", ".ogg"]; // Remove the extension if it matches any in the list @@ -88,7 +79,6 @@ fn normalize_filename(input: &str) -> String { } }); - // Replace all underscores with spaces without_extension.replace("_", " ") } diff --git a/templates/index.jinja b/templates/soundboard.jinja similarity index 100% rename from templates/index.jinja rename to templates/soundboard.jinja