def testGetNextSongRandom(self): song = self.addSong(artist=self.addArtist(), filename=__file__) songs_api = api.songs() result = songs_api.getNextSong() self.assertEquals(result, song) # check if song has been added to history history_api = api.history() result = history_api.index() self.assertEqual(result["itemList"][0]["id"], song.id)
def play(self): songs_api = api.songs() while 1: if self.proc is None: song_instance = songs_api.getNextSong() if not os.path.exists(song_instance.Filename): print "File not found: %s" % song_instance.Filename continue print "Playing " + song_instance.Filename self.proc = subprocess.Popen( [self.mpg123, song_instance.Filename]) else: if not self.proc.poll() is None: self.proc = None time.sleep(0.5)
def play(self): songs_api = api.songs() while 1: if self.proc is None: song_instance = songs_api.getNextSong() if not os.path.exists(song_instance.Filename): print "File not found: %s" % song_instance.Filename continue print "Playing " + song_instance.Filename self.proc = subprocess.Popen( [self.mpg123, song_instance.Filename] ) else: if not self.proc.poll() is None: self.proc = None time.sleep(0.5)
def testGetNextSongFromQueue(self): song = self.addSong(artist=self.addArtist(), filename=__file__) # add to queue queue_api = api.queue() queue_api.set_user_id(self.user.id) queue_api.add(song.id) # get next song songs_api = api.songs() result = songs_api.getNextSong() self.assertEquals(result, song) # check if song has been added to history history_api = api.history() result = history_api.index() self.assertEqual(result["itemList"][0]["id"], song.id) # check if song has been removed from queue result = queue_api.index() self.assertEqual(len(result["itemList"]), 0)
def handle(self, *args, **options): pidFile = os.path.dirname( os.path.abspath(__file__) ) + "/../../daemon.pid" if options["start"] or options["fg"]: if (options["host"] is None or options["port"] is None or options["password"] is None ): print "Required arguments: host, port, password" self.print_help("jukebox_shout", "help") return if os.path.exists(pidFile): print "Daemon already running, pid file exists" return pid = daemon.pidfile.TimeoutPIDLockFile( pidFile, 10 ) self.shout = shout.Shout() print "Using libshout version %s" % shout.version() self.shout.audio_info = { shout.SHOUT_AI_BITRATE: "128", shout.SHOUT_AI_SAMPLERATE: "44100", shout.SHOUT_AI_CHANNELS: "2" } self.shout.name = "Democratic Jukebox" self.shout.url = "http://" + options["host"] + ":" + \ options["port"] + "/stream" self.shout.mount = "/stream" self.shout.port = int(options["port"]) self.shout.user = "******" self.shout.password = options["password"] self.shout.genre = "Mixed" self.shout.description = "Your democratic music player" self.shout.host = options["host"] self.shout.ogv = 0 self.shout.format = "mp3" try: self.shout.open() self.shout.close() except shout.ShoutException as exception: print "Error: " + str(exception) return if options["start"]: print "Starting jukebox_shout daemon..." self.daemon = daemon.DaemonContext( uid=os.getuid(), gid=os.getgid(), pidfile=pid, working_directory=os.getcwd(), detach_process=True, signal_map={ SIGTSTP: self.shutdown, SIGABRT: self.skipSong } ) with self.daemon: self.shout.open() print "Register player" pid = int(open(pidFile).read()) players_api = api.players() players_api.add(pid) songs_api = api.songs() while 1: self.sendfile(songs_api.getNextSong()) elif options["fg"]: self.shout.open() print "Register player" pid = os.getpid() players_api = api.players() players_api.add(pid) songs_api = api.songs() while 1: song = songs_api.getNextSong() self.sendfile(song) elif options["stop"]: if not os.path.exists(pidFile): print "Daemon not running" return print "Stopping daemon..." pid = int(open(pidFile).read()) os.kill(pid, SIGTSTP) print "Unregister player " + str(pid) players_api = api.players() players_api.remove(pid) else: self.print_help("jukebox_shout", "help")
def getNextSong(self): songs_api = api.songs() return songs_api.getNextSong()
def handle(self, *args, **options): pidFile = os.path.dirname( os.path.abspath(__file__)) + "/../../daemon.pid" if options["start"] or options["fg"]: if (options["host"] is None or options["port"] is None or options["password"] is None): print "Required arguments: host, port, password" self.print_help("jukebox_shout", "help") return if os.path.exists(pidFile): print "Daemon already running, pid file exists" return pid = daemon.pidfile.TimeoutPIDLockFile(pidFile, 10) self.shout = shout.Shout() print "Using libshout version %s" % shout.version() self.shout.audio_info = { shout.SHOUT_AI_BITRATE: "128", shout.SHOUT_AI_SAMPLERATE: "44100", shout.SHOUT_AI_CHANNELS: "2" } self.shout.name = "Democratic Jukebox" self.shout.url = "http://" + options["host"] + ":" + \ options["port"] + "/stream" self.shout.mount = "/stream" self.shout.port = int(options["port"]) self.shout.user = "******" self.shout.password = options["password"] self.shout.genre = "Mixed" self.shout.description = "Your democratic music player" self.shout.host = options["host"] self.shout.ogv = 0 self.shout.format = "mp3" try: self.shout.open() self.shout.close() except shout.ShoutException as exception: print "Error: " + str(exception) return if options["start"]: print "Starting jukebox_shout daemon..." self.daemon = daemon.DaemonContext( uid=os.getuid(), gid=os.getgid(), pidfile=pid, working_directory=os.getcwd(), detach_process=True, signal_map={ SIGTSTP: self.shutdown, SIGABRT: self.skipSong }) with self.daemon: self.shout.open() print "Register player" pid = int(open(pidFile).read()) players_api = api.players() players_api.add(pid) songs_api = api.songs() while 1: self.sendfile(songs_api.getNextSong()) elif options["fg"]: self.shout.open() print "Register player" pid = os.getpid() players_api = api.players() players_api.add(pid) songs_api = api.songs() while 1: song = songs_api.getNextSong() self.sendfile(song) elif options["stop"]: if not os.path.exists(pidFile): print "Daemon not running" return print "Stopping daemon..." pid = int(open(pidFile).read()) os.kill(pid, SIGTSTP) print "Unregister player " + str(pid) players_api = api.players() players_api.remove(pid) else: self.print_help("jukebox_shout", "help")