Add command to show recommendations. (#593)

* Add command to show recommendations.

This adds a command `similar selected|current` which enables searching for
track recommendations for playlists, albums as well as single tracks.

* Make sure to only send 5 seed items in total.

* Add docs for recommendation bindings to the README
This commit is contained in:
HMH
2021-09-07 15:01:06 +02:00
committed by GitHub
parent 547cd6b0ef
commit d17c66f8ad
10 changed files with 166 additions and 11 deletions

View File

@@ -134,6 +134,7 @@ pub enum Command {
NewPlaylist(String),
Sort(SortKey, SortDirection),
Logout,
ShowRecommendations(TargetMode),
}
impl fmt::Display for Command {
@@ -193,6 +194,7 @@ impl fmt::Display for Command {
Command::NewPlaylist(name) => format!("new playlist {}", name),
Command::Sort(key, direction) => format!("sort {} {}", key, direction),
Command::Logout => "logout".to_string(),
Command::ShowRecommendations(mode) => format!("similar {}", mode),
};
write!(f, "{}", repr)
}
@@ -422,6 +424,14 @@ pub fn parse(input: &str) -> Option<Command> {
}
}
"logout" => Some(Command::Logout),
"similar" => args
.get(0)
.and_then(|target| match *target {
"selected" => Some(TargetMode::Selected),
"current" => Some(TargetMode::Current),
_ => None,
})
.map(Command::ShowRecommendations),
"noop" => Some(Command::Noop),
_ => None,
}