69 lines
2.0 KiB
Rust
69 lines
2.0 KiB
Rust
use crate::{
|
|
commands::{
|
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
|
ResponseParserError,
|
|
},
|
|
filter::parse_filter,
|
|
};
|
|
|
|
pub struct SearchAddPl;
|
|
|
|
impl Command for SearchAddPl {
|
|
type Response = ();
|
|
const COMMAND: &'static str = "searchaddpl";
|
|
|
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
|
let playlist_name = parts
|
|
.next()
|
|
.ok_or(RequestParserError::UnexpectedEOF)?
|
|
.to_string();
|
|
|
|
let filter = parse_filter(&mut parts)?;
|
|
|
|
let mut sort_or_window_or_position = parts.next();
|
|
let mut sort = None;
|
|
if let Some("sort") = sort_or_window_or_position {
|
|
sort = Some(
|
|
parts
|
|
.next()
|
|
.ok_or(RequestParserError::UnexpectedEOF)?
|
|
.to_string(),
|
|
);
|
|
sort_or_window_or_position = parts.next();
|
|
}
|
|
|
|
let mut window = None;
|
|
if let Some("window") = sort_or_window_or_position {
|
|
let w = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
|
window = Some(
|
|
w.parse()
|
|
.map_err(|_| RequestParserError::SyntaxError(0, w.to_string()))?,
|
|
);
|
|
sort_or_window_or_position = parts.next();
|
|
}
|
|
|
|
let mut position = None;
|
|
if let Some("position") = sort_or_window_or_position {
|
|
let p = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
|
position = Some(
|
|
p.parse()
|
|
.map_err(|_| RequestParserError::SyntaxError(0, p.to_string()))?,
|
|
);
|
|
}
|
|
|
|
debug_assert!(parts.next().is_none());
|
|
|
|
Ok((
|
|
Request::SearchAddPl(playlist_name, filter, sort, window, position),
|
|
"",
|
|
))
|
|
}
|
|
|
|
fn parse_response(
|
|
parts: ResponseAttributes<'_>,
|
|
) -> Result<Self::Response, ResponseParserError> {
|
|
debug_assert!(parts.is_empty());
|
|
Ok(())
|
|
}
|
|
}
|