0.3.2. get_audio subcommand.
This commit is contained in:
parent
ef50c64d87
commit
4b70b0708d
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -47,7 +47,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "monokakido"
|
name = "monokakido"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"miniserde",
|
"miniserde",
|
||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "monokakido"
|
name = "monokakido"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A Rust library for parsing and interpreting the Monokakido dictionary format."
|
description = "A Rust library for parsing and interpreting the Monokakido dictionary format."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use monokakido::{Error, MonokakidoDict};
|
use monokakido::{Error, MonokakidoDict};
|
||||||
|
|
||||||
fn print_help() {
|
fn print_help() {
|
||||||
|
@ -46,6 +48,16 @@ fn list_audio(dict_name: &str, keyword: &str) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_audio(dict_name: &str, id: &str) -> Result<(), Error> {
|
||||||
|
let id = id.strip_suffix(".aac").unwrap_or(id);
|
||||||
|
let mut dict = MonokakidoDict::open(dict_name)?;
|
||||||
|
let aac = dict.audio.as_mut().ok_or(Error::MissingAudio)?.get(id)?;
|
||||||
|
let mut stdout = std::io::stdout().lock();
|
||||||
|
// TODO: for ergonomics/failsafe, check if stdout is a TTY
|
||||||
|
stdout.write_all(aac)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn list_dicts() -> Result<(), Error> {
|
fn list_dicts() -> Result<(), Error> {
|
||||||
for dict in MonokakidoDict::list()? {
|
for dict in MonokakidoDict::list()? {
|
||||||
println!("{}", dict?);
|
println!("{}", dict?);
|
||||||
|
@ -63,6 +75,13 @@ fn main() {
|
||||||
Err(Error::InvalidArg)
|
Err(Error::InvalidArg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some("get_audio") => {
|
||||||
|
if let (Some(dict_name), Some(id)) = (args.next(), args.next()) {
|
||||||
|
get_audio(&dict_name, &id)
|
||||||
|
} else {
|
||||||
|
Err(Error::InvalidArg)
|
||||||
|
}
|
||||||
|
}
|
||||||
Some("list_items") => {
|
Some("list_items") => {
|
||||||
if let (Some(dict_name), Some(keyword)) = (args.next(), args.next()) {
|
if let (Some(dict_name), Some(keyword)) = (args.next(), args.next()) {
|
||||||
list_items(&dict_name, &keyword)
|
list_items(&dict_name, &keyword)
|
||||||
|
@ -82,7 +101,7 @@ fn main() {
|
||||||
print_help();
|
print_help();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(Error::InvalidArg),
|
_ => Err(Error::InvalidSubcommand),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
|
|
|
@ -25,6 +25,8 @@ pub enum Error {
|
||||||
FmtError,
|
FmtError,
|
||||||
IndexDoesntExist,
|
IndexDoesntExist,
|
||||||
XmlError,
|
XmlError,
|
||||||
|
MissingAudio,
|
||||||
|
InvalidSubcommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<IoError> for Error {
|
impl From<IoError> for Error {
|
||||||
|
|
Loading…
Reference in a new issue