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: add audioitem for echo spot #255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 25 additions & 7 deletions flask_ask/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,32 @@ def __init__(self, speech=''):
self._response = {}
self._response['directives'] = []

def play(self, stream_url, offset=0, opaque_token=None):
def play(self, stream_url, offset=0, opaque_token=None, title=None, subtitle=None, art=None, bgImg=None):
"""Sends a Play Directive to begin playback and replace current and enqueued streams."""

self._response['shouldEndSession'] = True
directive = self._play_directive('REPLACE_ALL')
directive['audioItem'] = self._audio_item(stream_url=stream_url, offset=offset, opaque_token=opaque_token)
directive['audioItem'] = self._audio_item(stream_url=stream_url,
offset=offset,
opaque_token=opaque_token,
title=title,
subtitle=subtitle,
art=art,
bgImg=bgImg)
self._response['directives'].append(directive)
return self

def enqueue(self, stream_url, offset=0, opaque_token=None):
def enqueue(self, stream_url, offset=0, opaque_token=None, title=None, subtitle=None, art=None, bgImg=None):
"""Adds stream to the queue. Does not impact the currently playing stream."""
directive = self._play_directive('ENQUEUE')
audio_item = self._audio_item(stream_url=stream_url,
offset=offset,
push_buffer=False,
opaque_token=opaque_token)
opaque_token=opaque_token
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're missing a comma here

title=title,
subtitle=subtitle,
art=art,
bgImg=bgImg)
audio_item['stream']['expectedPreviousToken'] = current_stream.token

directive['audioItem'] = audio_item
Expand All @@ -394,10 +404,11 @@ def _play_directive(self, behavior):
directive['type'] = 'AudioPlayer.Play'
directive['playBehavior'] = behavior
return directive

def _audio_item(self, stream_url=None, offset=0, push_buffer=True, opaque_token=None):

def _audio_item(self, stream_url=None, offset=0, push_buffer=True, opaque_token=None,
title=None, subtitle=None, art=None, bgImg=None):
"""Builds an AudioPlayer Directive's audioItem and updates current_stream"""
audio_item = {'stream': {}}
audio_item = {'stream': {}, 'metadata' : {}}
stream = audio_item['stream']

# existing stream
Expand All @@ -415,6 +426,13 @@ def _audio_item(self, stream_url=None, offset=0, push_buffer=True, opaque_token=

if push_buffer: # prevents enqueued streams from becoming current_stream
push_stream(stream_cache, context['System']['user']['userId'], stream)

metadata = audio_item['metadata']
metadata['title'] = title
metadata['subtitle'] = subtitle
metadata['art'] = {'sources' : [{'url' : art}]}
metadata['backgroundImage'] = {'sources' : [{'url' : art }]}

return audio_item

def stop(self):
Expand Down