예제 #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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
0
def queue_song(song_name, artist_name):
    app.logger.debug("Queuing song %s by %s" % (song_name, artist_name))

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

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

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

    # Queue the track in the list of song_ids
    queue.enqueue_track(song)
    stream_url = api.get_stream_url(song)
    card_text = render_template("queue_song_queued",
                                song=song['title'],
                                artist=song['artist'])
    if "albumArtRef" in queue.current_track():
        thumbnail = api.get_thumbnail(
            queue.current_track()['albumArtRef'][0]['url'])
    else:
        thumbnail = None
    return audio().enqueue(stream_url) \
        .standard_card(title=card_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
예제 #6
0
def play_similar_song_radio():
    if len(queue.song_ids) == 0:
        return statement("Please play a song to start radio")

    if api.is_indexing():
        return statement("Please wait for your tracks to finish 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("Sorry, I couldn't find that 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)

    thumbnail = api.get_thumbnail(queue.current_track()['albumArtRef'][0]['url'])
    speech_text = "Playing %s by %s" % (song['title'], song['artist'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
예제 #7
0
def play_song(song_name, artist_name):
    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("Sorry, I couldn't find that song")

    # Start streaming the first track
    first_song_id = queue.reset([song])
    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 %s by %s" % (song['title'], song['artist'])
    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='')
예제 #8
0
def play_different_album():
    # TODO -- can we do this without a subscription?
    if not api.use_store:
        return statement(render_template("not_supported_without_store"))

    api = GMusicWrapper.generate_api()

    current_track = queue.current_track()

    if current_track is None:
        return statement(render_template("play_different_album_no_track"))

    album = api.get_album_by_artist(artist_name=current_track['artist'],
                                    album_id=current_track['albumId'])

    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)

    speech_text = render_template("play_album_text",
                                  album=album['name'],
                                  artist=album['albumArtist'])
    return audio(speech_text).play(stream_url)
예제 #9
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='')
예제 #10
0
def currently_playing():
    if api.is_indexing():
        return statement("Please wait for your tracks to finish indexing")

    track = queue.current_track()

    if track is None:
        return audio("Nothing is playing right now")

    thumbnail = api.get_thumbnail(queue.current_track())
    return statement("The current track is %s by %s" % (track['title'],
                                                        track['artist'])) \
        .standard_card(title="The current track is",
                       text='%s by %s' % (track['title'], track['artist']),
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
예제 #11
0
def play_song_radio(song_name, artist_name, album_name):
    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 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'])


    if song is False:
        return statement("Sorry, I couldn't find that 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)

    thumbnail = api.get_thumbnail(queue.current_track()['albumArtRef'][0]['url'])
    speech_text = "Playing %s by %s" % (song['title'], song['artist'])
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
예제 #12
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)
예제 #13
0
def currently_playing():
    track = queue.current_track()

    if track == None:
        return audio("Nothing is playing right now")

    return audio("The current track is %s by %s" %
                 (track['title'], track['artist']))
예제 #14
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)
예제 #15
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 next_song()
예제 #16
0
def thumbs_down():
    if len(queue.song_ids) == 0:
        return statement("Please play a song to vote")

    if api.is_indexing():
        return statement("Please wait for your tracks to finish indexing")

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

    return statement("Downvoted")
예제 #17
0
def currently_playing():
    if api.is_indexing():
        return statement("Please wait for your tracks to finish indexing")

    track = queue.current_track()

    if track is None:
        return audio("Nothing is playing right now")

    return audio("The current track is %s by %s" %
                 (track['title'], track['artist']))
예제 #18
0
def play_promoted_songs():
    app.logger.debug("Fetching songs that you have up voted.")

    promoted_songs = api.get_promoted_songs()
    if promoted_songs is False:
        return statement(render_template("play_promoted_songs_no_songs"))

    first_song_id = queue.reset(promoted_songs)
    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_promoted_songs_text")
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
예제 #19
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"))

    thumbnail = api.get_thumbnail(
        queue.current_track()['albumArtRef'][0]['url'])
    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)
예제 #20
0
def finished():
    # Scrobble if Last.fm is setup
    if environ.get('LAST_FM_ACTIVE'):
        song_info = queue.current_track()

        if song_info is not None and 'title' in song_info and 'artist' in song_info:
            from ..utils import last_fm

            last_fm.scrobble(
                song_info['title'],
                song_info['artist'],
                environ['LAST_FM_SESSION_KEY']
            )

    queue.next()
    return empty_response()
예제 #21
0
def play_promoted_songs():
    app.logger.debug("Fetching songs that you have up voted.")

    promoted_songs = api.get_promoted_songs()
    if promoted_songs is False:
        return statement("Sorry, I couldnt find any up voted songs.")

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

    thumbnail = api.get_thumbnail(
        queue.current_track()['albumArtRef'][0]['url'])
    speech_text = "Playing your upvoted songs."
    return audio(speech_text).play(stream_url) \
        .standard_card(title=speech_text,
                       text='',
                       small_image_url=thumbnail,
                       large_image_url=thumbnail)
예제 #22
0
def play_different_album():
    api = GMusicWrapper.generate_api()

    current_track = queue.current_track()

    if current_track is None:
        return statement("Sorry, there's no album playing currently")

    album = api.get_album_by_artist(artist_name=current_track['artist'], album_id=current_track['albumId'])

    if album is False:
        return statement("Sorry, I couldn't find any albums.")

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

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

    speech_text = "Playing album %s by %s" % (album['name'], album['albumArtist'])
    return audio(speech_text).play(stream_url)
예제 #23
0
def play_song(song_name, artist_name):
    app.logger.debug(
        "Fetching song %s by %s" %
        (song_name,
         artist_name))  # TODO: fix the "song by artist" retrieval system

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

    if song is False:
        return statement("Sorry, I couldn't find that song")

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

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