Ejemplo n.º 1
0
    def handle(self, handler_input):
        language_prompts = handler_input.attributes_manager.request_attributes[
            "_"]
        persistent_attributes = handler_input.attributes_manager.persistent_attributes

        if persistent_attributes.get("playback_session_data") is not None:
            token = persistent_attributes["playback_session_data"]['token']
            url = persistent_attributes["playback_session_data"]['url']
            offset = persistent_attributes["playback_session_data"]["offset"]
            title = persistent_attributes["playback_session_data"]["title"]
            subtitle = "Episode {}".format(token)

        else:
            playlist = populate_playlist_from_rss(rss_url)
            index = len(playlist) - 1
            token = playlist[index]['token']
            url = playlist[index]['url']
            offset = 0
            title = playlist[index]['title']
            subtitle = "Episode {}".format(token)

            handler_input.response_builder.speak(
                random.choice(language_prompts["PLAY_LATEST_EPISODE"]))

            persistent_attributes['playlist'] = playlist
            persistent_attributes["playback_session_data"] = {
                'token': token,
                'url': url,
                'offset': offset,
                'title': title,
                'index': index,
                'loop': False,
                'shuffle': False
            }
            handler_input.attributes_manager.save_persistent_attributes()

        audio_directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(stream=Stream(token=token,
                                               url=url,
                                               offset_in_milliseconds=offset),
                                 metadata=AudioItemMetadata(
                                     title=title, subtitle=subtitle)))
        return (handler_input.response_builder.add_directive(
            audio_directive).set_should_end_session(True).response)
Ejemplo n.º 2
0
    def handle(self, handler_input):
        language_prompts = handler_input.attributes_manager.request_attributes[
            "_"]
        persistent_attributes = handler_input.attributes_manager.persistent_attributes

        playlist = populate_playlist_from_rss(rss_url)
        token = handler_input.request_envelope.request.intent.slots[
            "EpisodeNumber"].value
        if token is None:
            token = handler_input.request_envelope.request.intent.slots[
                "OrdinalNumber"].value
        index = int(token) - 1
        url = playlist[index]['url']
        offset = 0
        title = playlist[index]['title']
        subtitle = "Episode {}".format(token)
        persistent_attributes['playlist'] = playlist
        persistent_attributes["playback_session_data"] = {
            'next_track_queued': False,
            'token': token,
            'url': url,
            'offset': offset,
            'title': title,
            'index': index,
            'loop': False,
            'shuffle': False
        }
        handler_input.attributes_manager.save_persistent_attributes()

        speech_output = random.choice(
            language_prompts["PLAYING_CHOSEN_EPISODE"]).format(token)

        audio_directive = PlayDirective(
            play_behavior=PlayBehavior.REPLACE_ALL,
            audio_item=AudioItem(stream=Stream(token=token,
                                               url=url,
                                               offset_in_milliseconds=offset),
                                 metadata=AudioItemMetadata(
                                     title=title, subtitle=subtitle)))
        return (
            handler_input.response_builder.speak(speech_output).add_directive(
                audio_directive).set_should_end_session(True).response)
Ejemplo n.º 3
0
    def handle(self, handler_input):
        language_prompts = handler_input.attributes_manager.request_attributes[
            "_"]
        persistent_attributes = handler_input.attributes_manager.persistent_attributes

        token = persistent_attributes["playback_session_data"]["token"]
        index = int(token) - 1
        old_playlist = persistent_attributes['playlist']
        new_playlist = populate_playlist_from_rss(rss_url)
        persistent_attributes['playlist'] = new_playlist
        persistent_attributes["playback_session_data"].update({
            "index": index,
            "shuffle": False
        })
        handler_input.attributes_manager.save_persistent_attributes()

        speech_output = random.choice(language_prompts["SHUFFLE_OFF"])

        return (handler_input.response_builder.speak(
            speech_output).set_should_end_session(True).response)