Browse Source

Refresh, falls Stream abgebrochen ist

rbs-nas 11 months ago
parent
commit
368909a5a2
2 changed files with 31 additions and 12 deletions
  1. 1 0
      .gitignore
  2. 30 12
      main.py

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.venv/

+ 30 - 12
main.py

@@ -6,15 +6,33 @@ client = MPDClient()
 client.timeout = 60
 client.connect("localhost", 6600)
 
-title = ""
-station = ""
-
-while(True):
-    info = client.currentsong()
-    if station != info["name"]:
-        station = info["name"]
-        print(station)
-    if title != info["title"]:
-        title = info["title"]
-        print(title)
-    time.sleep(10)
+
+def main():
+    title = ""
+    station = ""
+    elapsed = ""
+
+    while(True):
+        stats = client.status()
+        if elapsed == stats.get("elapsed", "0"):
+            refresh(stats["song"])
+        elapsed = stats.get("elapsed", "0")
+
+        info = client.currentsong()
+        if station != info.get("name", ""):
+            station = info.get("name", "")
+            print(station)
+        if title != info.get("title", ""):
+            title = info.get("title", "")
+            print(title)
+        time.sleep(10)
+
+
+def refresh(song):
+    client.stop()
+    time.sleep(1)
+    client.play(song)
+
+
+if __name__ == "__main__":
+    main()