client.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/python3
  2. import tornado.ioloop, tornado.web, os
  3. import mplayer_ctl
  4. class Index(tornado.web.RequestHandler):
  5. def get(self):
  6. self.redirect("/web/index.html", permanent=True)
  7. class PlayerControl(tornado.web.RequestHandler):
  8. def get(self):
  9. cmd = None
  10. c = self.get_argument('cmd')
  11. if c == "new_artist_stream":
  12. cmd = mplayer_ctl.Cmd(mplayer_ctl.CMD_NEW_ARTIST_STREAM, {
  13. "name" : self.get_argument('name')
  14. })
  15. elif c == "stop_stream":
  16. cmd = mplayer_ctl.Cmd(mplayer_ctl.CMD_STOP_STREAM)
  17. if cmd is not None:
  18. print("Adding command:", cmd)
  19. mplayer_ctl.cmd_queue.insert(0, cmd)
  20. self.redirect("/")
  21. urls = [
  22. (r"/", Index),
  23. (r"/player_control", PlayerControl),
  24. ]
  25. settings = {
  26. "static_path" : os.path.join(os.path.dirname(__file__), "web"),
  27. "static_url_prefix" : "/web/",
  28. "debug" : True,
  29. }
  30. app = tornado.web.Application(urls, **settings)
  31. if __name__ == "__main__":
  32. print("Yams PI client")
  33. # Kick off mplayer control thread
  34. mplayer_ctl.start({
  35. "streaming_url" : "http://yozh.devt.de:9092",
  36. "default_url" : "http://web:gemasuxx@devt.de:5051/pleasuredome",
  37. })
  38. # Kick off tornado
  39. app.listen(80)
  40. tornado.ioloop.IOLoop.instance().start()