def test_video_app_validator(): """Tests the VideoAppValidator""" alexa_test = AlexaTest(handler) alexa_test.test([ TestItem( IntentRequestBuilder("OrpheusIntent", skill_settings).with_slot("pellicula", True).build(), expected_video_item=VideoItem("https://", Metadata("Orpheus et Eurydike"))) ]) with pytest.raises(AssertionError): alexa_test.test([ TestItem(IntentRequestBuilder("OrpheusIntent", skill_settings).build(), expected_video_item=VideoItem( "https://", Metadata("Orpheus et Eurydike"))) ]) with pytest.raises(AssertionError): alexa_test.test([ TestItem(IntentRequestBuilder("OrpheusIntent", skill_settings).with_slot( "pellicula", True).build(), expected_video_item=VideoItem( "https://", Metadata("Orpheus sine Eurydiki"))) ]) with pytest.raises(AssertionError): alexa_test.test([ TestItem(IntentRequestBuilder("OrpheusIntent", skill_settings).with_slot( "pellicula", True).build(), expected_video_item=VideoItem( "", Metadata("Orpheus sine Eurydike"))) ])
def handle(self, handler_input): # type: (HandlerInput) -> Response speak_output = "Okay. I've put 60 seconds on the clock. Let's begin!" gameSession.start() handler_input.response_builder.set_card( ui.StandardCard( title="Card Match Game", text="Welcome to Card Match Game!", image=ui.Image( small_image_url= "https://d2o906d8ln7ui1.cloudfront.net/images/BT7_Background.png", large_image_url= "https://d2o906d8ln7ui1.cloudfront.net/images/BT2_Background.png" ))) ##### comment codes below for online simulation handler_input.response_builder.add_directive( LaunchDirective( VideoItem( source= "https://cardmatchgamevideo.s3.amazonaws.com/clock1.mp4", metadata=Metadata(title="Card Match Game", subtitle="Clock")))) ### end of your comment return (handler_input.response_builder.speak(speak_output).ask( "You can ask the color of center left symbol").set_card( SimpleCard( "Card Match Game", "You can ask, 'the color of center left symbol'")).response )
def test_ask_with_video_app_launch_directive(self): directive = LaunchDirective(video_item=VideoItem( source=None, metadata=Metadata(title=None, subtitle=None))) response_factory = self.response_factory.add_directive(directive).ask( reprompt=None) assert response_factory.response.should_end_session is None, ( "The ask method of ResponseFactory fails to set the should_end " "session to None when video app directive" " presents")
def test_add_video_app_launch_directive(self): directive = LaunchDirective(video_item=VideoItem( source=None, metadata=Metadata(title=None, subtitle=None))) response_factory = self.response_factory.add_directive( directive).set_should_end_session(False) assert response_factory.response.directives[0] == directive, ( "The add_directive method of ResponseFactory fails to add " "LaunchDirective") assert response_factory.response.should_end_session is None, ( "The add_directive() method of ResponseFactory fails to " "remove should_end_session value")
def handle(self, handler_input): """ Creates a response for the given input Args: handler_input(HandlerInput): The input to the handler Returns: (Response) The response """ pellicula_slot = get_most_probable_value_for_slot( handler_input, "pellicula") if pellicula_slot is None: handler_input.response_builder.add_directive( PlayDirective( PlayBehavior.REPLACE_ALL, AudioItem(Stream(token="cantare_token", url="https://"), AudioItemMetadata("Highway to hell")))) else: handler_input.response_builder \ .add_directive(LaunchDirective(VideoItem("https://", Metadata("Orpheus et Eurydike")))) return handler_input.response_builder.response
def handle(self, handler_input): # type: (handler_input) -> Response logger.info(">>>>> In LaunchRequestHandler") interfaces = (ask_utils.request_util.get_supported_interfaces( handler_input).to_dict()) with open("parameters.json") as conf_data: conf = json.load(conf_data) locale = ask_utils.get_locale(handler_input) logger.debug(f"Locale is {locale}") # localized strings stored in language_strings.json with open("language_strings.json") as language_prompts: language_data = json.load(language_prompts) try: loc_data = language_data[locale[:2]] skill_name = loc_data['SKILL_NAME'] except KeyError: loc_data = language_data['en'] skill_name = loc_data['SKILL_NAME'] speak_output = loc_data['NO_VIDEO'] channel_id = loc_data['CHANNEL'] youtube_url = ( "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=" + channel_id + "&maxResults=1&order=date&type=video&key=" + conf['youtube_key']) success = True try: url = urllib.request.urlopen(youtube_url) except URLError as e: speak_output = loc_data['URL_ERROR'] logger.info("URLError %s", e) success = False except HTTPError as e: logger.info("HTTPError %s, %e", e, e.code) if e.code == 429: speak_output = loc_data['TOO_MANY_REQUESTS'] success = False if success: try: data = json.loads(url.read().decode()) videoId = data['items'][0]['id']['videoId'] yt = YouTube('https://www.youtube.com/watch?v=' + videoId) except Exception as e: speak_output = loc_data['YOUTUBE_ERROR'] success = False if success: logger.info("List of the available interfaces: %s", interfaces) if interfaces['video_app'] is not None: # device has video support for stream in yt.streams.order_by('resolution').desc(): if stream.includes_audio_track: break speak_output = loc_data[ 'VIDEO_MESSAGE'] + ": " + stream.title + ". " + yt.description logger.info("Video {}. " "Locale='{}'. " "channel_id='{}'. " "speak_output='{}'. " "youtube_key='{}'".format(stream, locale[:2], channel_id, speak_output, conf['youtube_key'])) directive = LaunchDirective(video_item=VideoItem( source=stream.url, metadata=Metadata(title=stream.title, subtitle=yt.description))) return (handler_input.response_builder.speak( speak_output).add_directive(directive).response) elif interfaces[ 'audio_player'] is not None: # device has only audio support (no video) stream = (yt.streams.filter( only_audio=True, subtype='mp4').order_by('fps').desc().first()) speak_output = loc_data[ 'AUDIO_MESSAGE'] + ": " + stream.title + ". " + yt.description logger.info("Audio {}. " "Locale='{}'. " "channel_id='{}'. " "speak_output='{}'. " "youtube_key='{}'".format(stream, locale[:2], channel_id, speak_output, conf['youtube_key'])) directive = PlayDirective( play_behavior=PlayBehavior.REPLACE_ALL, audio_item=AudioItem( stream=Stream(expected_previous_token=None, token=stream.url, url=stream.url, offset_in_milliseconds=0), metadata=AudioItemMetadata( title=stream.title, subtitle=yt.description, art=display.Image( content_description=stream.title, sources=[ display.ImageInstance(url=yt.thumbnail_url) ]), background_image=display.Image( content_description=stream.title, sources=[ display.ImageInstance(url=yt.thumbnail_url) ])))) return (handler_input.response_builder.speak( speak_output).add_directive( directive).set_should_end_session(True).response) else: speak_output = loc_data[ 'NO_INTERFACE'] + ": " + stream.title + ". " + yt.description return (handler_input.response_builder.speak(speak_output).response)