class Player: def __init__(self, library_manager): pygame.init() pygame.mixer.init() self.library_manager = library_manager self.webapi = Webclient() try: self.webapi.login(setting.GUSER, setting.GPASS) except: sys.stderr.write('Problem with authentication on Google server\n') def play(self, songId): f = open('tostream.mp3', 'w') song = self.webapi.get_stream_audio(songId) f.write(song) f.close() #songFile = StringIO.StringIO(song) pygame.mixer.music.load('tostream.mp3') pygame.mixer.music.play() print('streaming audio: ' + songId) while pygame.mixer.music.get_busy(): pygame.time.Clock().tick(10)
class gMusicClient(object): logged_in = False api = None playlists = dict() library = dict() def __init__(self, email, password): self.api = Webclient() logged_in = False attempts = 0 if len(password) is 0: password = getpass("Google password:"******"title"] if song["artist"] == "": song_artist = "Unknown Artist" else: song_artist = song["artist"] if song["album"] == "": song_album = "Unknown Album" else: song_album = song["album"] if not (song_artist in self.library): albums_dict = dict() self.library[song_artist] = albums_dict if not (song_album in self.library[song_artist]): song_list = list() self.library[song_artist][song_album] = song_list self.library[song_artist][song_album].append(song) plists = self.api.get_all_playlist_ids(auto=True, user=True) for u_playlist, u_playlist_id in plists["user"].iteritems(): self.playlists[u_playlist] = self.api.get_playlist_songs(u_playlist_id[0]) self.playlists["Thumbs Up"] = [song for song in songs if song['rating'] == 5] def getSongStream(self, song): return self.api.get_stream_urls(song["id"]) def getStreamAudio(self, song): return self.api.get_stream_audio(song["id"]) def thumbsUp(self, song): try: song["rating"] = 5 song_list = [song] self.api.change_song_metadata(song_list) print "Gave a Thumbs Up to {0} by {1} on Google Play.".format(song["title"].encode("utf-8"), song["artist"].encode("utf-8")) except: print "Error giving a Thumbs Up on Google Play."
chosen = playlist tracks = [] for x in chosen.get("tracks"): tracks.append(x) if raw_input("Shuffle?\n").lower() == "yes": random.shuffle(tracks) for song in tracks: print(song.get("trackId")) # info = mc.get_track_info(song.get("id")) # print(info.get("title")) f = open("test.mp3", "w") f.write(wc.get_stream_audio(song.get("trackId"), use_range_header=None)) f.close() pygame.mixer.init() pygame.mixer.music.load("test.mp3") pygame.mixer.music.play() while pygame.mixer.music.get_busy(): ctr = open("ctr.txt", "r") if ctr.read() == "pause": pygame.mixer.music.pause() while True: ctr = open("ctr.txt", "r") if ctr.read() == "play": pygame.mixer.music.unpause() break sleep(2) sleep(1)