Example #1
0
def play_song(song_name, artist_name):
    if not api.use_store and api.is_indexing():
        return statement(render_template("indexing"))

    app.logger.debug("Fetching song %s by %s" % (song_name, artist_name))

    # Fetch the song
    song = api.get_song(song_name, artist_name)

    if song is False:
        return statement(render_template("no_song"))

    # Start streaming the first track
    first_song_id = queue.reset([song])
    stream_url = api.get_stream_url(first_song_id)

    if "albumArtRef" in queue.current_track():
        thumbnail = api.get_thumbnail(queue.current_track()['albumArtRef'][0]['url'])
    else:
        thumbnail = None
    speech_text = render_template("play_song_text",
                                  song=song['title'],
                                  artist=song['artist'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
Example #2
0
def play_album(album_name, artist_name):
    if not api.use_store and api.is_indexing():
        return statement(render_template("indexing"))

    app.logger.debug("Fetching album %s" % album_name)

    # Fetch the album
    album = api.get_album(album_name, artist_name)

    if album is False:
        return statement(render_template("no_album"))

    # Setup the queue
    first_song_id = queue.reset(album['tracks'])

    # Start streaming the first track
    stream_url = api.get_stream_url(first_song_id)

    if "albumArtRef" in album:
        thumbnail = api.get_thumbnail(album['albumArtRef'])
    else:
        thumbnail = None
    speech_text = render_template("play_album_text",
                                  album=album['name'],
                                  artist=album['albumArtist'])

    app.logger.debug(speech_text)

    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
Example #3
0
def play_playlist(playlist_name):
    if not api.use_store and api.is_indexing():
        return statement(render_template("indexing"))

    # Retreve the content of all playlists in a users library
    all_playlists = api.get_all_user_playlist_contents()

    # Get the closest match
    best_match = api.closest_match(playlist_name, all_playlists)

    if best_match is None:
        return statement(render_template("play_playlist_no_match"))

    # Add songs from the playlist onto our queue
    first_song_id = queue.reset(best_match['tracks'])

    # Get a streaming URL for the first song in the playlist
    stream_url = api.get_stream_url(first_song_id)
    if "albumArtRef" in queue.current_track():
        thumbnail = api.get_thumbnail(queue.current_track()['albumArtRef'][0]['url'])
    else:
        thumbnail = None
    speech_text = render_template("play_playlist_text", playlist=best_match['name'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
Example #4
0
def play_artist(artist_name):
    if not api.use_store and api.is_indexing():
        return statement(render_template("indexing"))

    # Fetch the artist
    artist = api.get_artist(artist_name)

    if artist is False:
        return statement(render_template("play_artist_none", artist=artist_name))

    # Setup the queue
    first_song_id = queue.reset(artist['topTracks'])

    # Get a streaming URL for the top song
    stream_url = api.get_stream_url(first_song_id)

    thumbnail = api.get_thumbnail(artist['artistArtRef'])
    if api.use_store:
        speech_text = render_template("play_artist_text", artist=artist['name'])
    else:
        speech_text = render_template("play_artist_text_library", artist=artist['name'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
Example #5
0
def list_all_playlists():
    if api.is_indexing():
        return statement(render_template("indexing"))

    all_playlists = api.get_all_user_playlist_contents()
    playlist_names = []
    total_playlists = 0
    for i, match in enumerate(all_playlists):

        playlist_names.append(match['name'])
        total_playlists = i + 1

    # Adds "and" before the last playlist to sound more natural when speaking
    if len(playlist_names) >= 3:
        and_placement = len(playlist_names) - 1
        playlist_names.insert(and_placement,
                              render_template("playlist_separator"))

    app.logger.debug(playlist_names)
    playlist_names = ', '.join(playlist_names)

    speech_text = render_template("list_all_playlists_text",
                                  playlist_count=total_playlists,
                                  playlist_list=playlist_names)
    return statement(speech_text)
Example #6
0
def thumbs_down():
    if len(queue.song_ids) == 0:
        return statement(render_template("thumbs_no_song"))

    if api.is_indexing():
        return statement(render_template("indexing"))

    api.rate_song(queue.current_track(), '1')

    return statement(render_template("thumbs_down_text"))
Example #7
0
def play_library():
    if api.is_indexing():
        return statement(render_template("indexing"))

    tracks = api.library.values()
    first_song_id = queue.reset(tracks)
    first_song_id = queue.shuffle_mode(True)
    stream_url = api.get_stream_url(first_song_id)

    speech_text = render_template("play_library_text")
    return audio(speech_text).play(stream_url)
Example #8
0
def play_song_radio(song_name, artist_name, album_name):
    if not api.use_store and api.is_indexing():
        return statement(render_template("indexing"))

    app.logger.debug("Fetching song %s by %s from %s."
                     % (song_name, artist_name, album_name))

    # Fetch the song

    song = api.get_song(song_name, artist_name, album_name)

    if song is False:
        return statement(render_template("no_song"))

    if artist_name is not None:
        artist = api.get_artist(artist_name)
    else:
        artist = api.get_artist(song['artist'])

    if album_name is not None:
        album = api.get_album(album_name)
    else:
        album = api.get_album(song['album'])

    station_id = api.get_station("%s Radio" % song['title'],
                                 track_id=song['storeId'],
                                 artist_id=artist['artistId'],
                                 album_id=album['albumId'])

    tracks = api.get_station_tracks(station_id)

    first_song_id = queue.reset(tracks)
    stream_url = api.get_stream_url(first_song_id)

    if "albumArtRef" in queue.current_track():
        thumbnail = api.get_thumbnail(queue.current_track()['albumArtRef'][0]['url'])
    else:
        thumbnail = None
    speech_text = render_template("play_song_text",
                                  song=song['title'],
                                  artist=song['artist'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
Example #9
0
def play_similar_song_radio():
    # TODO -- can we do this without a subscription?
    if not api.use_store:
        return statement(render_template("not_supported_without_store"))

    if len(queue.song_ids) == 0:
        return statement(render_template("play_similar_song_radio_no_song"))

    if api.is_indexing():
        return statement(render_template("indexing"))

    # Fetch the song
    song = queue.current_track()
    artist = api.get_artist(song['artist'])
    album = api.get_album(song['album'])

    app.logger.debug("Fetching songs like %s by %s from %s"
                     % (song['title'], artist['name'], album['name']))

    if song is False:
        return statement(render_template("no_song"))

    station_id = api.get_station("%s Radio" % song['title'],
                                 track_id=song['storeId'],
                                 artist_id=artist['artistId'],
                                 album_id=album['albumId'])

    tracks = api.get_station_tracks(station_id)

    first_song_id = queue.reset(tracks)
    stream_url = api.get_stream_url(first_song_id)

    if "albumArtRef" in queue.current_track():
        thumbnail = api.get_thumbnail(queue.current_track()['albumArtRef'][0]['url'])
    else:
        thumbnail = None
    speech_text = render_template("play_song_radio_text",
                                  song=song['title'],
                                  artist=song['artist'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
Example #10
0
def play_artist_radio(artist_name):
    # TODO -- can we do this without a subscription?
    if not api.use_store:
        return statement(render_template("not_supported_without_store"))

    if not api.use_store and api.is_indexing():
        return statement(render_template("indexing"))

    # Fetch the artist
    artist = api.get_artist(artist_name)

    if artist is False:
        return statement(render_template("no_artist"))

    station_id = api.get_station("%s Radio" % artist['name'],
                                 artist_id=artist['artistId'])
    # TODO: Handle track duplicates (this may be possible using session ids)
    tracks = api.get_station_tracks(station_id)

    first_song_id = queue.reset(tracks)

    # Get a streaming URL for the top song
    stream_url = api.get_stream_url(first_song_id)

    # Fetch the album
    album = api.get_album(artist['album'])

    if "albumArtRef" in album:
        thumbnail = api.get_thumbnail(album['albumArtRef'])
    else:
        thumbnail = None
    speech_text = render_template("play_artist_radio_text",
                                  artist=artist['name'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
Example #11
0
def currently_playing():
    if api.is_indexing():
        return statement(render_template("indexing"))

    track = queue.current_track()

    if track is None:
        return audio(render_template("currently_playing_none"))

    if 'albumArtRef' in queue.current_track():
        thumbnail = api.get_thumbnail(
            queue.current_track()['albumArtRef'][0]['url'])
    else:
        thumbnail = None
    return statement(render_template("success_title")
                     + render_template("success_text",
                                       song=track['title'],
                                       artist=track['artist']))\
        .standard_card(title=render_template("success_title"),
                       text=render_template("success_text",
                                            song=track['title'],
                                            artist=track['artist']),
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)