def get_or_create_session(username, password): if username not in sessions: spotify = Spotify(username, password) if not spotify: return False else: sessions[username] = spotify return sessions[username]
def __init__(self, username, password): """ Initializer :param username: The username to connect to spotify with. :param password: The password to authenticate with. """ # Hook logging Logging.hook(3, Log.Debug) Logging.hook(2, Log.Info) Logging.hook(1, Log.Warn) Logging.hook(0, Log.Error) self.username = username self.spotify = Spotify(username, password, log_level=3)
def default(self, uri=None): if uri is None: raise cherrypy.HTTPError( 400, "A paramater was expected but not supplied.") spotify = Spotify(sys.argv[1], sys.argv[2]) track = spotify.objectFromURI(uri) if track is None: spotify.logout() raise cherrypy.HTTPError(404, "Could not find a track with that URI.") url = track.getFileURL() if not url: spotify.logout() raise cherrypy.HTTPError( 404, "Could not find a track URL for that URI.") spotify.logout() raise cherrypy.HTTPRedirect(url)
heartbeat_marker.wait(timeout=15) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Command line Spotify client') parser.add_argument('username', help='Your spotify username') parser.add_argument('password', nargs='?', default=None, help='<Optional> your spotify password') args = parser.parse_args() if args.password is None: args.password = getpass.getpass("Please enter your Spotify password") spotify = Spotify(args.username, args.password) if spotify.logged_in(): os.system("kill `pgrep -f respotify-helper` &> /dev/null") uri_resolver = subprocess.Popen([sys.executable, "respotify-helper.py", args.username, args.password]) with client: client.connect(host="localhost", port="6600") Thread(target=heartbeat_handler).start() command_loop() os.system("clear") with client: client.clear() client.disconnect() client = None heartbeat_marker.set() uri_resolver.kill()
mainloop.quit() def player_message(bus, msg, player, mainloop): if msg.type == gst.MESSAGE_EOS: player.set_state(gst.STATE_NULL) mainloop.quit() elif msg.type == gst.MESSAGE_ERROR: player.set_state(gst.STATE_NULL) print msg.parse_error() if len(sys.argv) < 3: print "Usage: " + sys.argv[0] + " <username> <password> [track URI]" else: sp = Spotify(sys.argv[1], sys.argv[2]) mainloop = gobject.MainLoop() player = gst.parse_launch('uridecodebin name=uridecode ! autoaudiosink') bus = player.get_bus() bus.add_signal_watch() bus.connect('message', player_message, player, mainloop) uri = sys.argv[3] if len(sys.argv) > 3 else "spotify:track:6NwbeybX6TDtXlpXvnUOZC" track = sp.objectFromURI(uri) print ','.join([a.getName() for a in track.getArtists()]) + ' - ' + track.getName() mp3_uri = track.getFileURL() player.get_by_name('uridecode').set_property('uri', mp3_uri)
def setUp(self): self.spotify = Spotify(USERNAME, PASSWORD) if not self.spotify.logged_in(): print "Login failed"