From 2715f3746be69dcf0ddb004545f31473a04a796e Mon Sep 17 00:00:00 2001 From: miro Date: Tue, 17 Sep 2024 23:36:20 +0100 Subject: [PATCH] feat:ovos.common_play.search.populate event new bus event to allow replacing the search results explicitly, meant for usage by ocp pipeline --- ovos_plugin_common_play/ocp/gui.py | 17 ++++--------- ovos_plugin_common_play/ocp/player.py | 36 +++++++++++++++++++-------- ovos_plugin_common_play/ocp/search.py | 11 -------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/ovos_plugin_common_play/ocp/gui.py b/ovos_plugin_common_play/ocp/gui.py index f16f4fe..b458fdb 100644 --- a/ovos_plugin_common_play/ocp/gui.py +++ b/ovos_plugin_common_play/ocp/gui.py @@ -1,7 +1,6 @@ import enum import time from os.path import join, dirname -from threading import Timer from time import sleep from ovos_bus_client.apis.gui import GUIInterface @@ -33,7 +32,6 @@ def __init__(self, bus=None): ui_directories=ui_dirs, config=gui_config) self.ocp_skills = {} # skill_id: meta - self.active_extension = gui_config.get("extension", "generic") self.search_mode_is_app = False self.persist_home_display = False self.event_scheduler_interface = None @@ -41,16 +39,11 @@ def __init__(self, bus=None): def bind(self, player): self.player = player super().set_bus(self.bus) - self.player.add_event("ovos.common_play.playback_time", - self.handle_sync_seekbar) - self.player.add_event('ovos.common_play.playlist.play', - self.handle_play_from_playlist) - self.player.add_event('ovos.common_play.search.play', - self.handle_play_from_search) - self.player.add_event('ovos.common_play.skill.play', - self.handle_play_skill_featured_media) - self.event_scheduler_interface = \ - EventSchedulerInterface(skill_id=OCP_ID, bus=self.bus) + self.player.add_event("ovos.common_play.playback_time", self.handle_sync_seekbar) + self.player.add_event('ovos.common_play.playlist.play', self.handle_play_from_playlist) + self.player.add_event('ovos.common_play.search.play', self.handle_play_from_search) + self.player.add_event('ovos.common_play.skill.play', self.handle_play_skill_featured_media) + self.event_scheduler_interface = EventSchedulerInterface(skill_id=OCP_ID, bus=self.bus) @property def video_backend(self): diff --git a/ovos_plugin_common_play/ocp/player.py b/ovos_plugin_common_play/ocp/player.py index 4caf1f7..67a2ccb 100644 --- a/ovos_plugin_common_play/ocp/player.py +++ b/ovos_plugin_common_play/ocp/player.py @@ -141,6 +141,8 @@ def register_bus_handlers(self): self.handle_set_repeat) self.add_event('ovos.common_play.repeat.unset', self.handle_unset_repeat) + self.add_event('ovos.common_play.search.populate', + self.handle_search_replace) # GUI Configuration Events self.add_event('ovos.common_play.gui.enable_app_timeout', @@ -648,7 +650,7 @@ def reset(self): """ self.stop() self.playlist.clear() - self.media.clear() + self.media.search_playlist.clear() self.set_media_state(MediaState.NO_MEDIA) self.shuffle = False self.loop_state = LoopState.NONE @@ -756,21 +758,33 @@ def handle_playback_ended(self, message): self.gui.handle_end_of_playback(message) # ovos common play bus api requests + @require_native_source() + def handle_search_replace(self, message): + LOG.debug("Updating search results playlist") + pl = message.data["playlist"] + replace = message.data.get("replace", False) + sort = message.data.get("sort_by_conf", True) + if replace: + if not pl: + self.media.search_playlist.clear() + else: + self.media.search_playlist.replace(pl) + else: + for e in pl: + self.media.search_playlist.add_entry(e) + if sort: + self.media.search_playlist.sort_by_conf() + self.gui.update_search_results() + @require_native_source() def handle_play_request(self, message): - LOG.debug("Received external OVOS playback request") + LOG.debug("Received playback request") repeat = message.data.get("repeat", False) if repeat: self.loop_state = LoopState.REPEAT - - if message.data.get("tracks"): - # backwards compat / old style - playlist = disambiguation = message.data["tracks"] - media = playlist[0] - else: - media = message.data.get("media") - playlist = message.data.get("playlist") or [media] - disambiguation = message.data.get("disambiguation") or [media] + media = message.data.get("media") + playlist = message.data.get("playlist") or [media] + disambiguation = message.data.get("disambiguation") or [] self.play_media(media, disambiguation, playlist) @require_native_source() diff --git a/ovos_plugin_common_play/ocp/search.py b/ovos_plugin_common_play/ocp/search.py index e65ce94..17be31b 100644 --- a/ovos_plugin_common_play/ocp/search.py +++ b/ovos_plugin_common_play/ocp/search.py @@ -72,14 +72,3 @@ def get_featured_skills(self, adult=False): return [s for s in skills if MediaType.ADULT not in s["media_type"] and MediaType.HENTAI not in s["media_type"]] - - def clear(self): - self.search_playlist.clear() - if self.gui: - self.gui.update_search_results() - - def replace(self, playlist): - self.search_playlist.clear() - self.search_playlist.replace(playlist) - if self.gui: - self.gui.update_search_results()