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

fix/coexistence_with_pipeline #115

Merged
merged 3 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
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
66 changes: 50 additions & 16 deletions ovos_plugin_common_play/ocp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,23 @@ def __init__(self, bus=None, lang=None, settings=None, skill_id=OCP_ID):
skill_id=OCP_ID)
self.media_intents = IntentContainer()
self.register_ocp_api_events()
self.register_media_intents()

self.add_event("mycroft.ready", self.replace_mycroft_cps, once=True)
skills_ready = self.bus.wait_for_response(
Message("mycroft.skills.is_ready",
context={"source": [self.skill_id],
"destination": ["skills"]}))
if skills_ready and skills_ready.data.get("status"):
self.remove_event("mycroft.ready")
self.replace_mycroft_cps(skills_ready)
if self.using_new_pipeline:
LOG.info("Using Classic OCP with experimental OCP pipeline")
else:
self.register_media_intents()

load_stream_extractors() # trigger a load + caching of OCP plugins
self.add_event("mycroft.ready", self.replace_mycroft_cps, once=True)
skills_ready = self.bus.wait_for_response(
Message("mycroft.skills.is_ready",
context={"source": [self.skill_id],
"destination": ["skills"]}))
if skills_ready and skills_ready.data.get("status"):
self.remove_event("mycroft.ready")
self.replace_mycroft_cps(skills_ready)

# report available plugins to ovos-core pipeline
self.handle_get_SEIs(Message("ovos.common_play.SEI.get"))

def handle_ping(self, message):
"""
Expand All @@ -83,11 +88,33 @@ def register_ocp_api_events(self):
"""
Register messagebus handlers for OCP events
"""
self.add_event('ovos.common_play.SEI.get', self.handle_get_SEIs)
self.add_event("ovos.common_play.ping", self.handle_ping)
self.add_event('ovos.common_play.home', self.handle_home)
# bus api shared with intents
self.add_event("ovos.common_play.search", self.handle_play)

def handle_get_SEIs(self, message):
"""report available StreamExtractorIds

Ported from ovos-media to accommodate migration period
and making old OCP compatible with the new pipeline

OCP plugins handle specific SEIs and return a real stream / extra metadata

this moves parsing to playback time instead of search time

SEIs are identifiers of the format "{SEI}//{uri}"
that might be present in media results

seis are NOT uris, a uri comes after {SEI}//

eg. for the youtube plugin a skill can return
"youtube//https://youtube.com/watch?v=wChqNkd6F24"
"""
xtract = load_stream_extractors() # @lru_cache, its a lazy loaded singleton
self.bus.emit(message.response({"SEI": xtract.supported_seis}))

def handle_home(self, message=None):
"""
Handle ovos.common_play.home Messages and show the homescreen
Expand All @@ -96,7 +123,18 @@ def handle_home(self, message=None):
# homescreen / launch from .desktop
self.gui.show_home(app_mode=True)

@property
def using_new_pipeline(self) -> bool:
# TODO - default to True in ovos-core 0.1.0
# more info: https://github.com/OpenVoiceOS/ovos-core/pull/456
moved_to_pipelines = Configuration().get("intents", {}).get("experimental_ocp_pipeline")
return moved_to_pipelines

def register_ocp_intents(self, message=None):
if self.using_new_pipeline:
LOG.debug("skipping Classic OCP intent registration")
return

with self._intent_registration_lock:
if not self._intents_event.is_set():
LOG.info(f"OCP intents missing, registering for {self}")
Expand All @@ -117,12 +155,8 @@ def register_media_intents(self):
NOTE: uses the same format as mycroft .intent files, language
support is handled the same way
"""
# TODO - default to True in ovos-core 0.1.0
# more info: https://github.com/OpenVoiceOS/ovos-core/pull/456
moved_to_pipelines = Configuration().get("intents", {}).get("experimental_ocp_pipeline")
if moved_to_pipelines:
LOG.info("Using Classic OCP with experimental OCP pipeline")
LOG.debug("skipping Classic OCP intent registering")
if self.using_new_pipeline:
LOG.debug("skipping Classic OCP media type intents registration")
return

locale_folder = join(dirname(__file__), "res", "locale", self.lang)
Expand Down
8 changes: 6 additions & 2 deletions ovos_plugin_common_play/ocp/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ def stop(self):
# stop any search still happening
self.bus.emit(Message("ovos.common_play.search.stop"))

LOG.debug("clearing playlist")
self.playlist.clear() # needed to ensure next track doesnt track due to autoplay

LOG.debug("Stopping playback")
if self.active_backend in [PlaybackType.AUDIO_SERVICE,
PlaybackType.UNDEFINED]:
Expand Down Expand Up @@ -731,8 +734,9 @@ def handle_invalid_media(self, message):

def handle_playback_ended(self, message):
# TODO: When we get here, self.active_backend has been reset!
if self.settings.get("autoplay", True) and \
self.active_backend != PlaybackType.MPRIS:
if (self.settings.get("autoplay", True) and \
self.active_backend != PlaybackType.MPRIS and
len(self.playlist.entries)):
LOG.debug(f"Playing next (backend={repr(self.active_backend)}")
self.play_next()
return
Expand Down
Loading