Browse Source

no reset if playing

itec78 3 years ago
parent
commit
e47d45dbaa
1 changed files with 37 additions and 36 deletions
  1. 37 36
      playlistalo.py

+ 37 - 36
playlistalo.py

@@ -393,7 +393,7 @@ def setlastannounce(announcepos):
 
 def consume(song):
     if os.path.exists(song):
-        print ("consumo la canzone " + song)
+        print ("Consumo la canzone " + song)
         if song.split("/")[0] == "playlist":
             os.remove(song)
             if not [x for x in glob(os.path.dirname(song) + "/*") if not os.path.basename(x) == "last"]:
@@ -442,40 +442,41 @@ def plaympd():
     synctime = 5
     listlen = 10
 
-    if SHUFFLEUSERS:
-        shuffleusers()
-    if SHUFFLEFALLBACK:
-        shufflefallback()
-        
-    #stoppa e svuota
-    client.stop()
-    client.clear()
-    #cancella la cartella mpd
-    if os.path.exists("mpd"):
-        shutil.rmtree("mpd")
-        os.makedirs("mpd")
-    client.rescan()
-
-    #aggiunge l'annuncio iniziale
-    addstartannounce()
-    #resetta il lastannounce
-    setlastannounce(ANNOUNCEREPEAT)
-
-    #riempe la playlist
-    plt = listtot(listlen)
-    for f in plt:
-        print(f[0])
-        copyfile(f[0], "mpd/" + f[0])
-    client.rescan()
-    time.sleep(0.5)
-    for f in plt:
-        client.add(f[0])
-
-    #consuma il primo e fa play
-    consume(plt[0][0])
-
-    #mpdadd(client, listlen)
-    client.play(0)
+    if client.status()['state'] != "play":
+        if SHUFFLEUSERS:
+            shuffleusers()
+        if SHUFFLEFALLBACK:
+            shufflefallback()
+            
+        #stoppa e svuota
+        client.stop()
+        client.clear()
+        #cancella la cartella mpd
+        if os.path.exists("mpd"):
+            shutil.rmtree("mpd")
+            os.makedirs("mpd")
+        client.rescan()
+
+        #aggiunge l'annuncio iniziale
+        addstartannounce()
+        #resetta il lastannounce
+        setlastannounce(ANNOUNCEREPEAT)
+
+        #riempe la playlist
+        plt = listtot(listlen)
+        for f in plt:
+            print(f[0])
+            copyfile(f[0], "mpd/" + f[0])
+        client.rescan()
+        time.sleep(0.5)
+        for f in plt:
+            client.add(f[0])
+
+        #consuma il primo e fa play
+        consume(plt[0][0])
+
+        #mpdadd(client, listlen)
+        client.play(0)
 
     while True:
         # print("Current")
@@ -560,7 +561,7 @@ def mpdadd(client, listlen):
         
     #print (i)
     for x in client.playlistinfo()[i:]:
-        print("cancello " + x['file'])
+        print("Cancello " + x['file'])
         client.delete(i)
     #e rifa la playlist
     for f in plt[i-1:]: