Пример #1
0
def skip_to(song_name, artist_name):
    if song_name is None:
        return statement(render_template("skip_to_no_song"))

    if artist_name is None:
        artist_name = ""
    best_match = api.closest_match(song_name, queue.tracks, artist_name, 0)

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

    try:
        song, song_id = api.extract_track_info(best_match)
        index = queue.song_ids.index(song_id)
    except:
        return statement(render_template("skip_to_no_song_match"))

    queue.current_index = index
    stream_url = api.get_stream_url(queue.current())

    if "albumArtRef" in queue.current_track():
        thumbnail = api.get_thumbnail(
            queue.current_track()['albumArtRef'][0]['url'])
    else:
        thumbnail = None
    speech_text = render_template("skip_to_speech_text",
                                  song=queue.current_track()['title'],
                                  artist=queue.current_track()['artist'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
Пример #2
0
def skip_to(song_name, artist_name):
    if song_name is None:
        return statement("Please say a song name to use this feature")

    if artist_name is None:
        artist_name = ""
    best_match = api.closest_match(song_name, queue.tracks, artist_name, 30)

    if best_match is None:
        return statement("Sorry, I couldn't find a close enough match.")

    try:
        song, song_id = api.extract_track_info(best_match)
        index = queue.song_ids.index(song_id)
    except:
        return statement("Sorry, I couldn't find that song in the queue")

    queue.current_index = index
    stream_url = api.get_stream_url(queue.current())

    thumbnail = api.get_thumbnail(queue.current_track())
    speech_text = "Skipping to %s by %s" % (queue.current_track()['title'],
                                            queue.current_track()['artist'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)