def redirect_to_stream(song_id): api = GMusicWrapper.generate_api() stream_url = api.get_google_stream_url(song_id) app.logger.debug('URL is %s' % stream_url) return redirect(stream_url, code=302)
class GMusicWrapperLogUnitTests(unittest.TestCase): """ Unit tests of the GMusicWrapper log functionality """ def setUp(self): surpress_warnings() logger = logging.getLogger() self.api = GMusicWrapper(getenv("GOOGLE_EMAIL"), getenv("GOOGLE_PASSWORD"), logger) def tearDown(self): pass @log_capture() def test_graceful_degradation_of_log(self, capture): """ Makes sure logging degrades gracefully """ self.api.log("test") capture.check(('root', 'DEBUG', 'test'), )
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("You must first play a song") # Fetch the song song = api.get_song(song_name, artist_name) if song is False: return statement("Sorry, I couldn't find that song") # Queue the track in the list of song_ids # queue.enqueue_track(song) //OLD if GMusicWrapper.use_library_first(): song_id = song['id'] else: song_id = song['storeId'] queue.enqueue_track(song, song_id) stream_url = api.get_stream_url(song) card_text = "Queued %s by %s." % (song['title'], song['artist']) thumbnail = api.get_thumbnail(song) return audio().enqueue(stream_url) \ .standard_card(title=card_text, text='', small_image_url=thumbnail, large_image_url=thumbnail)
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)
def nearly_finished(): next_id = queue.up_next() if next_id != None: api = GMusicWrapper.generate_api() stream_url = api.get_stream_url(next_id) return audio().enqueue(stream_url)
def list_latest_album_by_artist(artist_name): # 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() latest_album = api.get_latest_artist_albums(artist_name=artist_name) return statement(latest_album)
def shuffle_on(): if len(queue.song_ids) == 0: return statement("There are no songs to shuffle.") api = GMusicWrapper.generate_api() # Start streaming the first track in the new shuffled list first_song_id = queue.shuffle_mode(True) stream_url = api.get_stream_url(first_song_id) return audio().enqueue(stream_url)
def prev_song(): prev_id = queue.prev() if prev_id == None: return audio("You can't go back any farther in the queue") else: api = GMusicWrapper.generate_api() stream_url = api.get_stream_url(prev_id) return audio().play(stream_url)
def next_song(): next_id = queue.next() if next_id == None: return audio("There are no more songs on the queue") else: api = GMusicWrapper.generate_api() stream_url = api.get_stream_url(next_id) return audio().play(stream_url)
def resume(): next_id = queue.current() if next_id == None: return audio("There are no songs on the queue") else: api = GMusicWrapper.generate_api() stream_url = api.get_stream_url(next_id) return audio().enqueue(stream_url)
def play_artist_radio(artist_name): api = GMusicWrapper.generate_api() # TODO: Handle track duplicates? tracks = api.get_station_tracks("IFL") # Get a streaming URL for the first song first_song_id = queue.reset(tracks) stream_url = api.get_stream_url(first_song_id) speech_text = "Playing music from your personalized station" return audio(speech_text).play(stream_url)
def play_album_by_artist(artist_name): api = GMusicWrapper.generate_api() album = api.get_album_by_artist(artist_name=artist_name) 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)
def play_song(song_name, artist_name): api = GMusicWrapper.generate_api() queue.reset() app.logger.debug("Fetching song %s by %s" % (song_name, artist_name)) # Fetch the song song = api.get_song(song_name, artist_name=artist_name) if song == False: return statement("Sorry, I couldn't find that song") # Start streaming the first track stream_url = api.get_stream_url(song['storeId']) speech_text = "Playing song %s by %s" % (song['title'], song['artist']) return audio(speech_text).play(stream_url)
def play_artist(artist_name): api = GMusicWrapper.generate_api() # Fetch the artist artist = api.get_artist(artist_name) if artist == False: return statement("Sorry, I couldn't find that artist") # 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) speech_text = "Playing top tracks from %s" % artist['name'] return audio(speech_text).play(stream_url)
def play_album_by_artist(artist_name): api = GMusicWrapper.generate_api() album = api.get_album_by_artist(artist_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) speech_text = render_template("play_album_text", album=album['name'], artist=album['albumArtist']) return audio(speech_text).play(stream_url)
def play_album(album_name, artist_name): api = GMusicWrapper.generate_api() app.logger.debug("Fetching album %s by %s" % (album_name, artist_name)) # Fetch the album album = api.get_album(album_name, artist_name=artist_name) if album == False: return statement("Sorry, I couldn't find that 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 = "Playing album %s by %s" % (album['name'], album['albumArtist']) return audio(speech_text).play(stream_url)
def play_artist_radio(artist_name): api = GMusicWrapper.generate_api() # Fetch the artist artist = api.get_artist(artist_name) if artist == False: return statement("Sorry, I couldn't find that artist") station_id = api.get_station("%s Radio" % artist['name'], artist_id=artist['artistId']) # TODO: Handle track duplicates 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) speech_text = "Playing %s radio" % artist['name'] return audio(speech_text).play(stream_url)
def play_latest_album_by_artist(artist_name): # 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() latest_album = api.get_latest_album(artist_name) if latest_album is False: return statement(render_template("no_albums")) # Setup the queue first_song_id = queue.reset(latest_album['tracks']) # Start streaming the first track stream_url = api.get_stream_url(first_song_id) speech_text = render_template("play_album_text", album=latest_album['name'], artist=latest_album['albumArtist']) return audio(speech_text).play(stream_url)
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)
def play_playlist(playlist_name): api = GMusicWrapper.generate_api() # 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) \ .simple_card(title="Gee Music", content=speech_text)
def list_latest_album_by_artist(artist_name): api = GMusicWrapper.generate_api() latest_album = api.get_latest_artist_albums(artist_name=artist_name) return statement(latest_album)
def list_album_by_artists(artist_name): api = GMusicWrapper.generate_api() artist_album_list = api.get_artist_album_list(artist_name=artist_name) return statement(artist_album_list)
def setUp(self): surpress_warnings() logger = logging.getLogger() self.api = GMusicWrapper(getenv("GOOGLE_EMAIL"), getenv("GOOGLE_PASSWORD"), logger)