Skip to content

Commit

Permalink
refactor/ocp_modernize (#6)
Browse files Browse the repository at this point in the history
* refactor/ocp_modernize

return the new OCP MediaEntry/Playlist objects instead of needing to know a json structure

* fix/allow_ocp_objects

MediaEntry/Playlist/PluginStream objects should be allowed in ocp decorators

* utils 0.0.38 compat
  • Loading branch information
JarbasAl authored Jun 21, 2024
1 parent 9775198 commit 3e5b165
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
76 changes: 45 additions & 31 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
from os.path import join, dirname


from ovos_utils.ocp import MediaType, PlaybackType
from ovos_workshop.backwards_compat import MediaType, PlaybackType, Playlist, MediaEntry
from ovos_workshop.decorators import ocp_search, ocp_featured_media
from ovos_workshop.skills.common_play import OVOSCommonPlaybackSkill
from tunein import TuneIn


class TuneInSkill(OVOSCommonPlaybackSkill):
def __init__(self, *args, **kwargs):
super().__init__(supported_media = [MediaType.RADIO],
skill_icon=join(dirname(__file__), "res", "tunein.png"),
super().__init__(supported_media=[MediaType.RADIO],
skill_icon=join(dirname(__file__), "tunein.png"),
*args, **kwargs)

@ocp_featured_media()
def featured_media(self):
return [{
"match_confidence": 90,
"media_type": MediaType.RADIO,
"uri": ch.stream,
"playback": PlaybackType.AUDIO,
"image": ch.image,
"bg_image": ch.image,
"skill_icon": self.skill_icon,
"title": ch.title,
"artist": ch.artist,
"author": "TuneIn",
"length": 0
} for ch in TuneIn.featured()]
pl = Playlist(media_type=MediaType.RADIO,
title="TuneIn (Featured Stations)",
playback=PlaybackType.AUDIO,
skill_id=self.skill_id,
artist="TuneIn",
match_confidence=100,
skill_icon=self.skill_icon)
pl += [MediaEntry(media_type=MediaType.RADIO,
uri=ch.direct_stream,
title=ch.title,
playback=PlaybackType.AUDIO,
image=ch.image,
skill_id=self.skill_id,
artist=ch.artist,
match_confidence=90,
length=-1, # live stream
skill_icon=self.skill_icon)
for ch in TuneIn.featured()]
return pl

@ocp_search()
def search_tunein(self, phrase, media_type):
Expand All @@ -46,16 +51,25 @@ def search_tunein(self, phrase, media_type):
score = base_score + ch.match(phrase)
if self.voc_match(ch.title, "radio"):
score += 5
yield {
"match_confidence": min(100, score),
"media_type": MediaType.RADIO,
"uri": ch.stream,
"playback": PlaybackType.AUDIO,
"image": ch.image,
"bg_image": ch.image,
"skill_icon": self.skill_icon,
"title": ch.title,
"artist": ch.artist,
"author": "TuneIn",
"length": 0
}
yield MediaEntry(media_type=MediaType.RADIO,
uri=ch.stream,
title=ch.title,
playback=PlaybackType.AUDIO,
image=ch.image,
skill_id=self.skill_id,
artist=ch.artist,
match_confidence=min(100, score),
length=-1, # live stream
skill_icon=self.skill_icon)


if __name__ == "__main__":
from ovos_utils.messagebus import FakeBus
from ovos_utils.log import LOG

LOG.set_level("DEBUG")

s = TuneInSkill(bus=FakeBus(), skill_id="t.fake")
for r in s.search_tunein("secret agent", MediaType.RADIO):
print(r)
# MediaEntry(uri='http://ice6.somafm.com/secretagent-128-mp3', title='SomaFM: Secret Agent', artist='SomaFM: Secret Agent', match_confidence=100, skill_id='t.fake', playback=<PlaybackType.AUDIO: 2>, status=<TrackState.DISAMBIGUATION: 1>, media_type=<MediaType.RADIO: 7>, length=-1, image='http://cdn-profiles.tunein.com/s2593/images/logoq.jpg', skill_icon='/home/miro/PycharmProjects/OCPSkills/skill-ovos-tunein/res/tunein.png', javascript='')
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ovos-utils >= 0.1.0a7
ovos-utils >= 0.0.38
ovos-bus-client>=0.0.9a1
ovos-workshop>=0.0.16a3
ovos-workshop>=0.0.16a39
tunein~=0.0,>=0.0.4a1
File renamed without changes

0 comments on commit 3e5b165

Please sign in to comment.