main.py 759 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import time
  2. from mpd import MPDClient
  3. client = MPDClient()
  4. client.timeout = 60
  5. client.connect("localhost", 6600)
  6. def main():
  7. title = ""
  8. station = ""
  9. elapsed = ""
  10. while(True):
  11. stats = client.status()
  12. if elapsed == stats.get("elapsed", "0"):
  13. refresh(stats["song"])
  14. elapsed = stats.get("elapsed", "0")
  15. info = client.currentsong()
  16. if station != info.get("name", ""):
  17. station = info.get("name", "")
  18. print(station)
  19. if title != info.get("title", ""):
  20. title = info.get("title", "")
  21. print(title)
  22. time.sleep(10)
  23. def refresh(song):
  24. client.stop()
  25. time.sleep(1)
  26. client.play(song)
  27. if __name__ == "__main__":
  28. main()