2023-04-10 00:13:18 +02:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
use musichoard::{
|
|
|
|
database::{
|
2023-04-10 21:36:43 +02:00
|
|
|
json::{JsonDatabase, JsonDatabaseFileBackend},
|
2023-04-10 00:13:18 +02:00
|
|
|
DatabaseWrite,
|
|
|
|
},
|
|
|
|
library::{
|
2023-04-10 21:36:43 +02:00
|
|
|
beets::{BeetsLibrary, BeetsLibraryCommandExecutor},
|
2023-04-10 00:13:18 +02:00
|
|
|
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();
|
|
|
|
|
2023-04-10 22:03:04 +02:00
|
|
|
let mut beets = BeetsLibrary::new(Box::new(
|
|
|
|
BeetsLibraryCommandExecutor::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");
|
|
|
|
|
2023-04-10 21:36:43 +02:00
|
|
|
let mut database = JsonDatabase::new(Box::new(JsonDatabaseFileBackend::new(
|
|
|
|
&opt.database_file_path,
|
|
|
|
)));
|
2023-04-10 00:13:18 +02:00
|
|
|
|
|
|
|
database
|
|
|
|
.write(&collection)
|
|
|
|
.expect("failed to write to the database");
|
|
|
|
}
|