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

@@ -576,6 +576,25 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
return Ok(CommandResult::Consumed(None));
}
Command::ShowRecommendations(mode) => {
let queue = self.queue.clone();
let library = self.library.clone();
let target: Option<Box<dyn ListItem>> = match mode {
TargetMode::Current => self.queue.get_current().map(|t| t.as_listitem()),
TargetMode::Selected => {
let content = self.content.read().unwrap();
content.get(self.selected).map(|t| t.as_listitem())
}
};
if let Some(mut target) = target {
let view = target.open_recommendations(queue.clone(), library.clone());
return match view {
Some(view) => Ok(CommandResult::View(view)),
None => Ok(CommandResult::Consumed(None)),
};
}
}
_ => {}
};