Skip to content

Commit

Permalink
Merge pull request #2 from jgoguen/numeric-prefix-support
Browse files Browse the repository at this point in the history
Support more numeric prefixes
  • Loading branch information
techno-disaster authored Jul 25, 2024
2 parents b91c32b + 2eab2cc commit edc69cd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
39 changes: 39 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ name = "lyricsrs"

[dependencies]
lofty = "0.20.1"
regex = "1.10.5"
reqwest = { version = "0.12.5", features = ["json", "blocking"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
22 changes: 12 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;

use lofty::file::AudioFile;
use lofty::probe::Probe;
use regex::Regex;
use std::path::Path;
use std::path::PathBuf;
use std::sync::atomic::AtomicUsize;
Expand Down Expand Up @@ -120,16 +121,17 @@ async fn parse_song_path(file_path: &Path, music_dir: &Path, successful_count: A
}

fn remove_numbered_prefix(s: &str) -> String {
// Find the index of the first dot
if let Some(index) = s.find('.') {
// Check if characters before the dot are digits
if s[..index].chars().all(|c| c.is_digit(10)) {
// Return substring after the dot
return s[index + 1..].trim().to_string();
}
}
// If no valid prefix found, return the original string
s.to_string()
let re = Regex::new(r"^(\d*\s?[\-\._\s]+)(.+)$").unwrap();
let matches = re.captures(s);
let name = match matches {
Some(v) => match v.get(2) {
Some(n) => n.as_str(),
None => s,
},
None => s,
};

return name.to_string();
}

fn get_audio_duration(file_path: &PathBuf) -> Duration {
Expand Down
8 changes: 7 additions & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ use std::path::PathBuf;

use tokio::fs;

pub const SONGS: [&str; 5] = [
pub const SONGS: [&str; 11] = [
"Taylor Swift/THE TORTURED POETS DEPARTMENT: THE ANTHOLOGY/1. Fortnight (Ft. Post Malone).flac",
"Taylor Swift/THE TORTURED POETS DEPARTMENT: THE ANTHOLOGY/2. The Tortured Poets Department.mp3",
"Taylor Swift/THE TORTURED POETS DEPARTMENT: THE ANTHOLOGY/3. My Boy Only Breaks His Favorite Toys.m4a",
"Taylor Swift/reputation/2. End Game.flac",
"Lou Reed/The Best of Lou Reed/8. Perfect Day.m4a",
"Heilung/Drif/01 Asja.flac",
"Heilung/Drif/02 - Anoana.flac",
"LINKIN PARK/Hybrid Theory/09-A Place for my Head.mp3",
"LINKIN PARK/LIVING THINGS/6.CASTLE OF GLASS.flac",
"Our Lady Peace/Clumsy/5_4AM.mp3",
"Our Lady Peace/Spiritual Machines/04 _ In Repair.mp3",
];

pub const BASE_DIR: &str = "Music";
Expand Down

0 comments on commit edc69cd

Please sign in to comment.