Exemple #1
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)
Exemple #2
0
def play_playlist(playlist_name):
    # 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("Sorry, I couldn't find that playlist in your library.")

    # 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)
    try:
        thumbnail = api.get_thumbnail(queue.current_track()['albumArtRef'][0]['url'])
    except:
        thumbnail = ""
    speech_text = "Playing songs from %s" % (best_match['name'])
    if (thumbnail != ""):
        return audio(speech_text).play(stream_url) \
                                 .standard_card(title=speech_text,
                                                text='',
                                                small_image_url=thumbnail,
                                                large_image_url=thumbnail)
    else:
        return audio(speech_text).play(stream_url) \
         .simple_card(title=speech_text, content='')
Exemple #3
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)
Exemple #4
0
def play_playlist(playlist_name):
    # Retreve the content of all playlists in a users library
    all_playlists = api.get_all_user_playlist_contents()

    # Give each playlist a score based on its similarity to the requested
    # playlist name
    request_name = playlist_name.lower().replace(" ", "")
    scored_playlists = []
    for i, playlist in enumerate(all_playlists):
        name = playlist['name'].lower().replace(" ", "")
        scored_playlists.append({
            'index': i,
            'name': name,
            'score': fuzz.ratio(name, request_name)
        })

    sorted_playlists = sorted(scored_playlists,
                              lambda a, b: b['score'] - a['score'])
    top_scoring = sorted_playlists[0]
    best_match = all_playlists[top_scoring['index']]

    # Make sure we have a decent match (the score is n where 0 <= n <= 100)
    if top_scoring['score'] < 80:
        return statement(
            "Sorry, I couldn't find that playlist in your library.")

    # 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)

    speech_text = "Playing songs from %s" % (best_match['name'])
    return audio(speech_text).play(stream_url)
Exemple #5
0
def list_all_playlists():
    if api.is_indexing():
        return statement("Please wait for your tracks to finish indexing")

    all_playlists = api.get_all_user_playlist_contents()
    playlist_names = []
    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, 'and')

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

    speech_text = "You have %s playlists in your library. They are, %s." % (
        total_playlists, playlist_names)
    return statement(speech_text)