Files
empidee/src/commands/music_database/getfingerprint.rs
h7x4 366f56da9e
Some checks failed
Build and test / build (push) Successful in 59s
Build and test / check (push) Failing after 58s
Build and test / docs (push) Successful in 1m21s
Build and test / test (push) Successful in 1m37s
commands: fix some syntax errors reporting literals
2024-12-14 00:19:25 +01:00

39 lines
1.1 KiB
Rust

use std::collections::HashMap;
use crate::commands::{
get_and_parse_property, Command, Request, RequestParserError, RequestParserResult,
ResponseAttributes, ResponseParserError,
};
pub struct GetFingerprint;
pub struct GetFingerprintResponse {
pub chromaprint: String,
}
impl Command for GetFingerprint {
type Response = GetFingerprintResponse;
const COMMAND: &'static str = "getfingerprint";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let uri = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let uri = uri
.parse()
.map_err(|_| RequestParserError::SyntaxError(1, uri.to_owned()))?;
debug_assert!(parts.next().is_none());
Ok((Request::GetFingerprint(uri), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
let parts: HashMap<_, _> = parts.into();
let chromaprint = get_and_parse_property!(parts, "chromaprint", Text);
Ok(GetFingerprintResponse { chromaprint })
}
}