Add database stats
This commit is contained in:
parent
c374a04417
commit
b415ebb509
26
src/lib.rs
26
src/lib.rs
|
@ -4,7 +4,7 @@ mod error;
|
|||
use error::{Error, MpdResult};
|
||||
use itertools::Itertools;
|
||||
mod structs;
|
||||
pub use structs::{Position, Status, Track};
|
||||
pub use structs::{Position, Stats, Status, Track};
|
||||
|
||||
/// some unprintable character to separate repeated keys
|
||||
const SEPARATOR: char = '\x02';
|
||||
|
@ -280,4 +280,28 @@ OK";
|
|||
let queue = read_playlist_info("OK".lines());
|
||||
assert_eq!(queue, Ok(vec![]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn de_stats_test() {
|
||||
let input_str = "uptime: 23691
|
||||
playtime: 11288
|
||||
artists: 2841
|
||||
albums: 2455
|
||||
songs: 40322
|
||||
db_playtime: 11620284
|
||||
db_update: 1588433046";
|
||||
let s: Stats = deserialize_response(input_str.lines()).unwrap();
|
||||
assert_eq!(
|
||||
s,
|
||||
Stats {
|
||||
uptime: Duration::from_secs(23691),
|
||||
playtime: Duration::from_secs(11288),
|
||||
artists: 2841,
|
||||
albums: 2455,
|
||||
songs: 40322,
|
||||
db_playtime: Duration::from_secs(11620284),
|
||||
db_update: 1588433046,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,23 @@ pub struct Status {
|
|||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
/// Database statistics as returned by the `stats` command.
|
||||
#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
|
||||
#[serde(default)]
|
||||
pub struct Stats {
|
||||
pub artists: u32,
|
||||
pub albums: u32,
|
||||
pub songs: u32,
|
||||
#[serde(deserialize_with = "de_time_int")]
|
||||
pub uptime: Duration,
|
||||
#[serde(deserialize_with = "de_time_int")]
|
||||
pub db_playtime: Duration,
|
||||
// TODO: this is a unix era. use some datetime for it
|
||||
pub db_update: u32,
|
||||
#[serde(deserialize_with = "de_time_int")]
|
||||
pub playtime: Duration,
|
||||
}
|
||||
|
||||
/// Deserialization helpers to handle the quirks of mpd’s output.
|
||||
mod helpers {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in New Issue
Block a user