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/ocp_skill_name_from_voc #220

Merged
merged 2 commits into from
Jul 11, 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
27 changes: 22 additions & 5 deletions ovos_workshop/skills/common_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +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.skill_voc_filename = skill_voc_filename
self._search_handlers = [] # added via decorators
self._featured_handlers = [] # added via decorators
self._current_query = None
Expand All @@ -78,6 +79,18 @@ def __init__(self, supported_media=None, skill_icon="", *args, **kwargs):
self.ocp_matchers = {}
super().__init__(*args, **kwargs)

def _read_skill_name_voc(self):
"""read voc file to allow requesting a skill by name"""
if self.skill_voc_filename:
for lang in self.native_langs:
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 and sort by str len
self.skill_aliases = sorted(list(set(self.skill_aliases)), reverse=True)

@property
def ocp_cache_dir(self):
"""path to cached .csv file with ocp entities data
Expand Down Expand Up @@ -142,6 +155,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,
Expand Down Expand Up @@ -337,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}))
Expand Down
Loading