From 25c01f4434936dab6cd1206ec61dcf2863ce7740 Mon Sep 17 00:00:00 2001 From: Craig Drummond Date: Sun, 13 Mar 2022 06:54:09 +0000 Subject: [PATCH] Number cue tracks from 1, should match LMS track number --- src/analyse.rs | 11 ++--------- src/cue.rs | 6 ++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/analyse.rs b/src/analyse.rs index 79ff425..344a0ef 100644 --- a/src/analyse.rs +++ b/src/analyse.rs @@ -57,8 +57,7 @@ fn get_file_list(db:&mut db::Db, mpath:&PathBuf, path:&PathBuf, track_paths:&mut if cue_file.exists() { // Found a CUE file, try to parse and then check if tracks exists in DB let this_cue_tracks = cue::parse(&pb, &cue_file); - let mut analyse = false; - for track in this_cue_tracks.iter() { + for track in this_cue_tracks { match track.track_path.strip_prefix(mpath) { Ok(tstripped) => { let spb = tstripped.to_path_buf(); @@ -66,7 +65,7 @@ fn get_file_list(db:&mut db::Db, mpath:&PathBuf, path:&PathBuf, track_paths:&mut match db.get_rowid(&sname) { Ok(id) => { if id<=0 { - analyse = true; + cue_tracks.push(track.clone()); } }, Err(_) => { } @@ -75,12 +74,6 @@ fn get_file_list(db:&mut db::Db, mpath:&PathBuf, path:&PathBuf, track_paths:&mut Err(_) => { } } } - - if analyse { - for track in this_cue_tracks { - cue_tracks.push(track); - } - } } else { let spb = stripped.to_path_buf(); let sname = String::from(spb.to_string_lossy()); diff --git a/src/cue.rs b/src/cue.rs index b1e0528..c244573 100644 --- a/src/cue.rs +++ b/src/cue.rs @@ -26,8 +26,7 @@ pub struct CueTrack { pub album_artist:String, pub genre:String, pub start:Duration, - pub duration:Duration, - pub analyse:bool + pub duration:Duration } pub fn parse(audio_path:&PathBuf, cue_path:&PathBuf) -> Vec { @@ -50,7 +49,7 @@ pub fn parse(audio_path:&PathBuf, cue_path:&PathBuf) -> Vec { Some((_, start)) => { let mut track_path = audio_path.clone(); let ext = audio_path.extension().unwrap().to_string_lossy(); - track_path.set_extension(format!("{}{}{}.mp3", ext, MARKER, resp.len())); + track_path.set_extension(format!("{}{}{}.mp3", ext, MARKER, resp.len()+1)); let ctrack = CueTrack { audio_path: audio_path.clone(), track_path: track_path, @@ -61,7 +60,6 @@ pub fn parse(audio_path:&PathBuf, cue_path:&PathBuf) -> Vec { genre: genre.clone(), start: start.clone(), duration: Duration::new(LAST_TRACK_DURATION, 0), - analyse: false }; resp.push(ctrack); },