mirror of
https://github.com/CDrummond/bliss-analyser.git
synced 2025-04-08 05:00:02 +03:00
parent
b91c2edafd
commit
2cb7dc0fa0
@ -5,6 +5,7 @@
|
||||
3. Use 'ffmpeg' commandline to decode files, and not ffmpeg libraries by
|
||||
defualt. Pass "--features=libav" to cargo to build against ffmpeg
|
||||
libraries.
|
||||
4. Add ability to specify LMS JSONRPC port.
|
||||
|
||||
0.2.3
|
||||
-----
|
||||
|
@ -133,6 +133,8 @@ analysis results. This will default to `bliss.db` in the current folder.
|
||||
* `lms` specifies the hostname, or IP address, of your LMS server. This is used
|
||||
when uploading the database file to LMS. This defaults to `127.0.0.1` If your LMS is
|
||||
password protected then use `user:pass@server` - e.g. `lms=pi:abc123@127.0.0.1`
|
||||
* `json` specifies the JSONRPC port number of your LMS server. This will defaul to
|
||||
9000.
|
||||
* `ignore` specifies the name and location of a file containing items to ignore
|
||||
in mixes. See the `Ignore` section later on for more details.
|
||||
|
||||
@ -156,6 +158,7 @@ analysis will be performed, instead the logging will inform you how many new
|
||||
tracks are to be analysed and how many old tracks are left in the database.
|
||||
* `-i` / `--ignore` Name and location of the file containing items to ignore.
|
||||
* `-L` / `--lms` Hostname, or IP address, of your LMS server.
|
||||
* `-J` / `--json` JSONRPC port number of your LMS server.
|
||||
* `-n` / `--numtracks` Specify maximum number of tracks to analyse.
|
||||
|
||||
Equivalent items specified in the INI config file (detailed above) will override
|
||||
|
11
src/main.rs
11
src/main.rs
@ -37,6 +37,7 @@ fn main() {
|
||||
let mut dry_run: bool = false;
|
||||
let mut task = "".to_string();
|
||||
let mut lms_host = "127.0.0.1".to_string();
|
||||
let mut lms_json_port:u16 = 9000;
|
||||
let mut max_num_files: usize = 0;
|
||||
let mut music_paths: Vec<PathBuf> = Vec::new();
|
||||
let mut max_threads: usize = 0;
|
||||
@ -55,6 +56,7 @@ fn main() {
|
||||
let logging_help = format!("Log level; trace, debug, info, warn, error. (default: {})", logging);
|
||||
let ignore_file_help = format!("File contains items to mark as ignored. (default: {})", ignore_file);
|
||||
let lms_host_help = format!("LMS hostname or IP address (default: {})", &lms_host);
|
||||
let lms_json_port_help = format!("LMS JSONRPC port (default: {})", &lms_json_port);
|
||||
let description = format!("Bliss Analyser v{}", VERSION);
|
||||
|
||||
// arg_parse.refer 'borrows' db_path, etc, and can only have one
|
||||
@ -69,6 +71,7 @@ fn main() {
|
||||
arg_parse.refer(&mut dry_run).add_option(&["-r", "--dry-run"], StoreTrue, "Dry run, only show what needs to be done (used with analyse task)");
|
||||
arg_parse.refer(&mut ignore_file).add_option(&["-i", "--ignore"], Store, &ignore_file_help);
|
||||
arg_parse.refer(&mut lms_host).add_option(&["-L", "--lms"], Store, &lms_host_help);
|
||||
arg_parse.refer(&mut lms_json_port).add_option(&["-J", "--json"], Store, &lms_json_port_help);
|
||||
arg_parse.refer(&mut max_num_files).add_option(&["-n", "--numfiles"], Store, "Maximum number of files to analyse");
|
||||
arg_parse.refer(&mut max_threads).add_option(&["-t", "--threads"], Store, "Maximum number of threads to use for analysis");
|
||||
arg_parse.refer(&mut task).add_argument("task", Store, "Task to perform; analyse, tags, ignore, upload, stopmixer.");
|
||||
@ -128,6 +131,10 @@ fn main() {
|
||||
Some(val) => { lms_host = val; }
|
||||
None => { }
|
||||
}
|
||||
match config.get(TOP_LEVEL_INI_TAG, "json") {
|
||||
Some(val) => { lms_json_port = val.parse::<u16>().unwrap(); }
|
||||
None => { }
|
||||
}
|
||||
match config.get(TOP_LEVEL_INI_TAG, "ignore") {
|
||||
Some(val) => { ignore_file = val; }
|
||||
None => { }
|
||||
@ -146,7 +153,7 @@ fn main() {
|
||||
}
|
||||
|
||||
if task.eq_ignore_ascii_case("stopmixer") {
|
||||
upload::stop_mixer(&lms_host);
|
||||
upload::stop_mixer(&lms_host, lms_json_port);
|
||||
} else {
|
||||
if db_path.len() < 3 {
|
||||
log::error!("Invalid DB path ({}) supplied", db_path);
|
||||
@ -161,7 +168,7 @@ fn main() {
|
||||
|
||||
if task.eq_ignore_ascii_case("upload") {
|
||||
if path.exists() {
|
||||
upload::upload_db(&db_path, &lms_host);
|
||||
upload::upload_db(&db_path, &lms_host, lms_json_port);
|
||||
} else {
|
||||
log::error!("DB ({}) does not exist", db_path);
|
||||
process::exit(-1);
|
||||
|
@ -17,24 +17,24 @@ fn fail(msg: &str) {
|
||||
process::exit(-1);
|
||||
}
|
||||
|
||||
pub fn stop_mixer(lms: &String) {
|
||||
pub fn stop_mixer(lms_host: &String, json_port: u16) {
|
||||
let stop_req = "{\"id\":1, \"method\":\"slim.request\",\"params\":[\"\",[\"blissmixer\",\"stop\"]]}";
|
||||
|
||||
log::info!("Asking plugin to stop mixer");
|
||||
let req = ureq::post(&format!("http://{}:9000/jsonrpc.js", lms)).send_string(&stop_req);
|
||||
let req = ureq::post(&format!("http://{}:{}/jsonrpc.js", lms_host, json_port)).send_string(&stop_req);
|
||||
if let Err(e) = req {
|
||||
log::error!("Failed to ask plugin to stop mixer. {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn upload_db(db_path: &String, lms: &String) {
|
||||
pub fn upload_db(db_path: &String, lms_host: &String, json_port: u16) {
|
||||
// First tell LMS to restart the mixer in upload mode
|
||||
let start_req = "{\"id\":1, \"method\":\"slim.request\",\"params\":[\"\",[\"blissmixer\",\"start-upload\"]]}";
|
||||
let mut port: u16 = 0;
|
||||
|
||||
log::info!("Requesting LMS plugin to allow uploads");
|
||||
|
||||
match ureq::post(&format!("http://{}:9000/jsonrpc.js", lms)).send_string(&start_req) {
|
||||
match ureq::post(&format!("http://{}:{}/jsonrpc.js", lms_host, json_port)).send_string(&start_req) {
|
||||
Ok(resp) => match resp.into_string() {
|
||||
Ok(text) => match text.find("\"port\":") {
|
||||
Some(s) => {
|
||||
@ -69,13 +69,13 @@ pub fn upload_db(db_path: &String, lms: &String) {
|
||||
Ok(meta) => {
|
||||
let buffered_reader = BufReader::new(file);
|
||||
log::info!("Length: {}", meta.len());
|
||||
match ureq::put(&format!("http://{}:{}/upload", lms, port))
|
||||
match ureq::put(&format!("http://{}:{}/upload", lms_host, port))
|
||||
.set("Content-Length", &meta.len().to_string())
|
||||
.set("Content-Type", "application/octet-stream")
|
||||
.send(buffered_reader) {
|
||||
Ok(_) => {
|
||||
log::info!("Database uploaded");
|
||||
stop_mixer(lms);
|
||||
stop_mixer(lms_host, json_port);
|
||||
}
|
||||
Err(e) => { fail(&format!("Failed to upload database. {}", e)); }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user