diff --git a/src/analyse.rs b/src/analyse.rs index 4619d52..662fcd4 100644 --- a/src/analyse.rs +++ b/src/analyse.rs @@ -19,8 +19,7 @@ use indicatif::{ProgressBar, ProgressStyle}; #[cfg(not(feature = "ffmpeg"))] use std::collections::HashSet; use std::convert::TryInto; -use std::fs::{DirEntry, File}; -use std::io::{BufRead, BufReader}; +use std::fs::DirEntry; use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; #[cfg(feature = "ffmpeg")] @@ -475,37 +474,6 @@ pub fn analyse_files(db_path: &str, mpaths: &Vec, dry_run: bool, keep_o db.close(); if changes_made && ignore_path.exists() && ignore_path.is_file() { log::info!("Updating 'ignore' flags"); - update_ignore(&db_path, &ignore_path); + db::update_ignore(&db_path, &ignore_path); } } - -pub fn read_tags(db_path: &str, mpaths: &Vec) { - let db = db::Db::new(&String::from(db_path)); - db.init(); - db.update_tags(&mpaths); - db.close(); -} - -pub fn export(db_path: &str, mpaths: &Vec, max_threads: usize, preserve_mod_times: bool) { - let db = db::Db::new(&String::from(db_path)); - db.init(); - db.export(&mpaths, max_threads, preserve_mod_times); - db.close(); -} - -pub fn update_ignore(db_path: &str, ignore_path: &PathBuf) { - let file = File::open(ignore_path).unwrap(); - let reader = BufReader::new(file); - let db = db::Db::new(&String::from(db_path)); - db.init(); - - db.clear_ignore(); - let mut lines = reader.lines(); - while let Some(Ok(line)) = lines.next() { - if !line.is_empty() && !line.starts_with("#") { - db.set_ignore(&line); - } - } - - db.close(); -} diff --git a/src/db.rs b/src/db.rs index 96f4b7c..ecfe8ac 100644 --- a/src/db.rs +++ b/src/db.rs @@ -13,6 +13,8 @@ use bliss_audio::{Analysis, AnalysisIndex}; use indicatif::{ProgressBar, ProgressStyle}; use rusqlite::{params, Connection}; use std::convert::TryInto; +use std::fs::File; +use std::io::{BufRead, BufReader}; use std::num::NonZeroUsize; use std::path::PathBuf; use std::process; @@ -444,3 +446,34 @@ impl Db { } } } + +pub fn read_tags(db_path: &str, mpaths: &Vec) { + let db = Db::new(&String::from(db_path)); + db.init(); + db.update_tags(&mpaths); + db.close(); +} + +pub fn export(db_path: &str, mpaths: &Vec, max_threads: usize, preserve_mod_times: bool) { + let db = Db::new(&String::from(db_path)); + db.init(); + db.export(&mpaths, max_threads, preserve_mod_times); + db.close(); +} + +pub fn update_ignore(db_path: &str, ignore_path: &PathBuf) { + let file = File::open(ignore_path).unwrap(); + let reader = BufReader::new(file); + let db = Db::new(&String::from(db_path)); + db.init(); + + db.clear_ignore(); + let mut lines = reader.lines(); + while let Some(Ok(line)) = lines.next() { + if !line.is_empty() && !line.starts_with("#") { + db.set_ignore(&line); + } + } + + db.close(); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a81c693..92fccbf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -200,7 +200,7 @@ fn main() { } if task.eq_ignore_ascii_case("tags") { - analyse::read_tags(&db_path, &music_paths); + db::read_tags(&db_path, &music_paths); } else if task.eq_ignore_ascii_case("ignore") { let ignore_path = PathBuf::from(&ignore_file); if !ignore_path.exists() { @@ -211,9 +211,9 @@ fn main() { log::error!("Ignore file ({}) is not a file", ignore_file); process::exit(-1); } - analyse::update_ignore(&db_path, &ignore_path); + db::update_ignore(&db_path, &ignore_path); } else if task.eq_ignore_ascii_case("export") { - analyse::export(&db_path, &music_paths, max_threads, preserve_mod_times); + db::export(&db_path, &music_paths, max_threads, preserve_mod_times); } else { let ignore_path = PathBuf::from(&ignore_file); analyse::analyse_files(&db_path, &music_paths, dry_run, keep_old, max_num_files, max_threads, &ignore_path, use_tags, preserve_mod_times);