Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:ovos.common_play.search.populate event #118

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions ovos_bus_client/apis/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,22 @@ def queue(self, tracks: list, source_message: Optional[Message] = None):
self.bus.emit(source_message.forward('ovos.common_play.playlist.queue',
{'tracks': tracks}))

@_ensure_message_kwarg()
def populate_search_results(self, tracks: list,
replace: bool = True,
sort_by_conf: bool = True,
source_message: Optional[Message] = None):
"""populate search results in OCP with new tracks
Args:
tracks: track dict or list of track dicts (OCP result style)
replace: if False, extend existing search, if True replace current search results
source_message: bus message that triggered this action
"""
tracks = self.norm_tracks(tracks)
self.bus.emit(source_message.forward('ovos.common_play.search.populate',
{"playlist": [t.as_dict for t in tracks],
"replace": replace, "sort_by_conf": sort_by_conf}))

@_ensure_message_kwarg()
def play(self, tracks: list, utterance=None, source_message: Optional[Message] = None):
"""Start playback.
Expand All @@ -353,12 +369,22 @@ def play(self, tracks: list, utterance=None, source_message: Optional[Message] =
source_message: bus message that triggered this action
"""
tracks = self.norm_tracks(tracks)

utterance = utterance or ''
tracks = [t.as_dict for t in tracks]
playlist = tracks
disambiguation = []
try:
from ovos_utils.ocp import Playlist, MediaEntry, PluginStream, dict2entry
if isinstance(tracks[0], Playlist):
playlist = tracks[0]
disambiguation = tracks
except ImportError as e:
LOG.warning("can't handle Playlist results properly, please update ovos-utils to >= 0.1.0")

media = playlist[0]
self.bus.emit(source_message.forward('ovos.common_play.play',
{"media": tracks[0],
"playlist": tracks,
{"media": media.as_dict,
"playlist": [t.as_dict for t in playlist],
"disambiguation": [t.as_dict for t in disambiguation],
"utterance": utterance}))

@_ensure_message_kwarg()
Expand Down
Loading