Update ignore syntax to allow adding SQL WHERE clauses.

This commit is contained in:
Craig Drummond 2022-03-06 11:31:02 +00:00
parent 6f8f3d52a9
commit e60a3c7b09
4 changed files with 25 additions and 12 deletions

2
Cargo.lock generated
View File

@ -113,7 +113,7 @@ dependencies = [
[[package]]
name = "bliss-analyser"
version = "0.0.1"
version = "0.0.2"
dependencies = [
"anyhow",
"argparse",

View File

@ -2,6 +2,7 @@
-----
1. Package vcruntime140.dll with Windows ZIP.
2. Update user docs.
3. Update ignore syntax to allow adding SQL WHERE clauses.
0.0.1
-----

View File

@ -258,19 +258,23 @@ accomplished be setting the `Ignore` column to `1` for such tracks. To make this
easier, `bliss-analyser` can read a text file containing items to ignore and
will update the database as appropriate.
This `ignore` file is a plain text file where each line contains the unique
path to be ignored. i.e. it could contain the complete path (relative to your
music folder) of a track, an album name (to exclude a whole album), or an artist
name (to exclude all tracks by the artist). e.g.
This `ignore` file is a plain text file where each line contains either:
1. The unique path to be ignored. i.e. it could contain the complete path
(relative to your music folder) of a track, an album name (to exclude a whole
album), or an artist name (to exclude all tracks by the artist).
2. An SQL selector. If so, line must start "SQL:" followed by code that will be
run after WHERE
```
ABBA/Gold - Greatest Hits/01 Dancing Queen.mp3
AC-DC/Power Up/
The Police/
SQL:Genre='Blues'
```
This would exclude 'Dancing Queen' by ABBA, all of AC/DC's 'Power Up', and all
tracks by 'The Police'
This would exclude 'Dancing Queen' by ABBA, all of AC/DC's 'Power Up', all
tracks by 'The Police', and all tracks with 'Genre' set to 'Blues'
Assuming `config.ini` is in the current folder and contains valid entries, this
is accomplished as follows:

View File

@ -249,11 +249,19 @@ impl Db {
}
}
pub fn set_ignore(&self, like:&str) {
log::info!("Ignore: {}", like);
match self.conn.execute(&format!("UPDATE Tracks SET Ignore=1 WHERE File LIKE \"{}%\"", like), []) {
Ok(_) => { },
Err(e) => { log::error!("Failed set Ignore column for '{}'. {}", like, e); }
pub fn set_ignore(&self, line:&str) {
log::info!("Ignore: {}", line);
if line.starts_with("SQL:") {
let sql = &line[4..];
match self.conn.execute(&format!("UPDATE Tracks Set Ignore=1 WHERE {}", sql), []) {
Ok(_) => { },
Err(e) => { log::error!("Failed set Ignore column for '{}'. {}", line, e); }
}
} else {
match self.conn.execute(&format!("UPDATE Tracks SET Ignore=1 WHERE File LIKE \"{}%\"", line), []) {
Ok(_) => { },
Err(e) => { log::error!("Failed set Ignore column for '{}'. {}", line, e); }
}
}
}
}