Add option to ignore files

This commit is contained in:
Craig Drummond 2022-02-16 12:17:28 +00:00
parent faedc0302b
commit 208d0e9b13
3 changed files with 49 additions and 8 deletions

View File

@ -10,6 +10,8 @@ use anyhow::{Result};
use bliss_audio::{library::analyze_paths_streaming};
use indicatif::{ProgressBar, ProgressStyle};
use std::convert::TryInto;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use crate::db;
use crate::tags;
@ -141,4 +143,20 @@ pub fn read_tags(db_path: &str, mpath: &PathBuf) {
db.init();
db.update_tags(&mpath);
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();
for (_index, line) in reader.lines().enumerate() {
let line = line.unwrap();
if !line.is_empty() && !line.starts_with("#") {
db.set_ignore(&line);
}
}
db.close();
}

View File

@ -191,7 +191,7 @@ impl Db {
let path = String::from(mpath.join(&dtags.file).to_string_lossy());
let ftags = tags::read(&path);
if ftags.duration!=dtags.duration || ftags.title!=dtags.title || ftags.artist!=dtags.artist || ftags.album!=dtags.album || ftags.genre!=dtags.genre {
match self.conn.execute("UPDATE Tracks SET Title=?, Artist=?, Album=?, Genre=?, Duration=? WHERE rowid=?);",
match self.conn.execute("UPDATE Tracks SET Title=?, Artist=?, Album=?, Genre=?, Duration=? WHERE rowid=?;",
params![ftags.title, ftags.artist, ftags.album, ftags.genre, ftags.duration, dtags.rowid]) {
Ok(_) => { },
Err(e) => { log::error!("Failed to update tags of '{}'. {}", dtags.file, e); }
@ -199,4 +199,18 @@ impl Db {
}
}
}
}
pub fn clear_ignore(&self) {
match self.conn.execute("UPDATE Tracks SET Ignore=0;", []) {
Ok(_) => { },
Err(e) => { log::error!("Failed clear Ignore column. {}", e); }
}
}
pub fn set_ignore(&self, like:&str) {
match self.conn.execute("UPDATE Tracks SET Ignore=1 WHERE File LIKE ?", params![like]) {
Ok(_) => { },
Err(e) => { log::error!("Failed set Ignore column for '{}'. {}", like, e); }
}
}
}

View File

@ -16,6 +16,7 @@ fn main() {
let mut db_path = "bliss.db".to_string();
let mut logging = "warn".to_string();
let mut music_path = ".".to_string();
let mut ignore_file = String::new();
let mut keep_old:bool = false;
let mut dry_run:bool = false;
let mut tags_only:bool = false;
@ -31,11 +32,7 @@ fn main() {
arg_parse.refer(&mut keep_old).add_option(&["-k", "--keep-old"], Store, "Don't remove tracks from DB if they don't exist");
arg_parse.refer(&mut dry_run).add_option(&["-r", "--dry-run"], Store, "Dry run, only show what needs to be done");
arg_parse.refer(&mut tags_only).add_option(&["-t", "--tags-only"], Store, "Re-read tags");
/*
TODO:
-i --ignore Update ignore column
-t --tags Re-read tags
*/
arg_parse.refer(&mut ignore_file).add_option(&["-i", "--ignore"], Store, "Update ignore status in DB");
arg_parse.parse_args_or_exit();
}
@ -70,6 +67,18 @@ fn main() {
if tags_only {
analyse::read_tags(&db_path, &mpath);
} else if !ignore_file.is_empty() {
let ignore_path = PathBuf::from(&ignore_file);
if !ignore_path.exists() {
log::error!("Ignore file ({}) does not exist", ignore_file);
process::exit(-1);
}
if !ignore_path.is_file() {
log::error!("Ignore file ({}) is not a file", ignore_file);
process::exit(-1);
}
analyse::update_ignore(&db_path, &ignore_path);
} else {
analyse::analyse_files(&db_path, &mpath, dry_run, keep_old);
}
analyse::analyse_files(&db_path, &mpath, dry_run, keep_old);
}