2023-04-10 00:13:18 +02:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
use musichoard::{
|
|
|
|
database::{
|
|
|
|
json::{DatabaseJson, DatabaseJsonFile},
|
|
|
|
DatabaseWrite,
|
|
|
|
},
|
|
|
|
library::{
|
|
|
|
beets::{Beets, SystemExecutor},
|
|
|
|
Library, Query,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(StructOpt)]
|
|
|
|
struct Opt {
|
|
|
|
#[structopt(
|
|
|
|
short = "b",
|
|
|
|
long = "beets-config",
|
|
|
|
name = "beets config file path",
|
|
|
|
parse(from_os_str)
|
|
|
|
)]
|
|
|
|
beets_config_file_path: Option<PathBuf>,
|
|
|
|
|
|
|
|
#[structopt(
|
|
|
|
short = "d",
|
|
|
|
long = "database",
|
|
|
|
name = "database file path",
|
|
|
|
default_value = "database.json",
|
|
|
|
parse(from_os_str)
|
|
|
|
)]
|
|
|
|
database_file_path: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let opt = Opt::from_args();
|
|
|
|
|
|
|
|
let mut beets = Beets::new(Box::new(
|
2023-04-10 20:48:44 +02:00
|
|
|
unsafe { SystemExecutor::default().config(opt.beets_config_file_path.as_deref()) },
|
2023-04-10 00:13:18 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
let collection = beets
|
|
|
|
.list(&Query::new())
|
|
|
|
.expect("failed to query the library");
|
|
|
|
|
|
|
|
let mut database = DatabaseJson::new(Box::new(DatabaseJsonFile::new(&opt.database_file_path)));
|
|
|
|
|
|
|
|
database
|
|
|
|
.write(&collection)
|
|
|
|
.expect("failed to write to the database");
|
|
|
|
}
|