Skip to content

Commit

Permalink
feat:ovos.common_play.search.populate event
Browse files Browse the repository at this point in the history
new bus event to allow replacing the search results explicitly, meant for usage by ocp pipeline
  • Loading branch information
JarbasAl committed Sep 17, 2024
1 parent 00097dd commit 2715f37
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
17 changes: 5 additions & 12 deletions ovos_plugin_common_play/ocp/gui.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -33,24 +32,18 @@ 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

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):
Expand Down
36 changes: 25 additions & 11 deletions ovos_plugin_common_play/ocp/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 0 additions & 11 deletions ovos_plugin_common_play/ocp/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 2715f37

Please sign in to comment.