From fb179a6bc2ac16be013a72063ffeb096960b015b Mon Sep 17 00:00:00 2001 From: miro Date: Thu, 11 Jul 2024 18:30:44 +0100 Subject: [PATCH 1/2] feat/ocp_skill_name_from_voc solve TODO, allow devs to specify a .voc file with skill name strings, instead of deriving from class name --- ovos_workshop/skills/common_play.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/ovos_workshop/skills/common_play.py b/ovos_workshop/skills/common_play.py index 5bc08224..44cab3a8 100644 --- a/ovos_workshop/skills/common_play.py +++ b/ovos_workshop/skills/common_play.py @@ -56,11 +56,13 @@ def ... vocab for starting playback is needed. """ - def __init__(self, supported_media=None, skill_icon="", *args, **kwargs): + def __init__(self, supported_media: List[MediaType] = None, + skill_icon: str = "", + skill_voc_filename: str = "", + *args, **kwargs): self.supported_media = supported_media or [MediaType.GENERIC] - skill_name = camel_case_split(self.__class__.__name__) - alt = skill_name.replace(" skill", "").replace(" Skill", "") - self.skill_aliases = [skill_name, alt] + self.skill_aliases = [] + self._read_skill_name_voc(skill_voc_filename) self._search_handlers = [] # added via decorators self._featured_handlers = [] # added via decorators @@ -78,6 +80,18 @@ def __init__(self, supported_media=None, skill_icon="", *args, **kwargs): self.ocp_matchers = {} super().__init__(*args, **kwargs) + def _read_skill_name_voc(self, skill_voc_filename: str): + """read voc file to allow requesting a skill by name""" + if skill_voc_filename: + for lang in self.native_langs: + self.skill_aliases += self.voc_list(skill_voc_filename, lang) + else: + skill_name = camel_case_split(self.__class__.__name__) + alt = skill_name.replace(" skill", "").replace(" Skill", "") + self.skill_aliases = [skill_name, alt] + # deduplicate + self.skill_aliases = list(set(self.skill_aliases)) + @property def ocp_cache_dir(self): """path to cached .csv file with ocp entities data @@ -142,6 +156,7 @@ def __handle_ocp_skills_get(self, message=None): it will search netflix instead of spotify """ message = message or Message("") + # TODO - aliases per lang self.bus.emit( message.reply('ovos.common_play.announce', {"skill_id": self.skill_id, From 55b328d62e282b6f0709e311e552254302609204 Mon Sep 17 00:00:00 2001 From: miro Date: Thu, 11 Jul 2024 19:11:47 +0100 Subject: [PATCH 2/2] feat/ocp_skill_name_from_voc solve TODO, allow devs to specify a .voc file with skill name strings, instead of deriving from class name --- ovos_workshop/skills/common_play.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ovos_workshop/skills/common_play.py b/ovos_workshop/skills/common_play.py index 44cab3a8..70a9da38 100644 --- a/ovos_workshop/skills/common_play.py +++ b/ovos_workshop/skills/common_play.py @@ -62,8 +62,7 @@ def __init__(self, supported_media: List[MediaType] = None, *args, **kwargs): self.supported_media = supported_media or [MediaType.GENERIC] self.skill_aliases = [] - self._read_skill_name_voc(skill_voc_filename) - + self.skill_voc_filename = skill_voc_filename self._search_handlers = [] # added via decorators self._featured_handlers = [] # added via decorators self._current_query = None @@ -80,17 +79,17 @@ def __init__(self, supported_media: List[MediaType] = None, self.ocp_matchers = {} super().__init__(*args, **kwargs) - def _read_skill_name_voc(self, skill_voc_filename: str): + def _read_skill_name_voc(self): """read voc file to allow requesting a skill by name""" - if skill_voc_filename: + if self.skill_voc_filename: for lang in self.native_langs: - self.skill_aliases += self.voc_list(skill_voc_filename, lang) - else: + self.skill_aliases += self.voc_list(self.skill_voc_filename, lang) + if not self.skill_aliases: skill_name = camel_case_split(self.__class__.__name__) alt = skill_name.replace(" skill", "").replace(" Skill", "") self.skill_aliases = [skill_name, alt] - # deduplicate - self.skill_aliases = list(set(self.skill_aliases)) + # deduplicate and sort by str len + self.skill_aliases = sorted(list(set(self.skill_aliases)), reverse=True) @property def ocp_cache_dir(self): @@ -352,11 +351,14 @@ def _register_decorated(self): super()._register_decorated() + # needs to be after super() because it needs self.config_core + self._read_skill_name_voc() # volunteer info to OCP self.bus.emit( Message('ovos.common_play.announce', {"skill_id": self.skill_id, "skill_name": self.skill_aliases[0], + "aliases": self.skill_aliases, "thumbnail": self.skill_icon, "media_types": self.supported_media, "featured_tracks": len(self._featured_handlers) >= 1}))