Fixed annouces

This commit is contained in:
itec78 2020-06-21 12:26:26 +02:00
parent a70905d5f9
commit bd3600e7b2
2 changed files with 35 additions and 10 deletions

View file

@ -5,6 +5,7 @@ import playlistalo
if __name__ == '__main__':
pl = playlistalo.listplaylist()
#pl = playlistalo.listtot()
#print ('\n'.join([", ".join(x) for x in pl]))
print ('\n'.join([x[0] for x in pl]))

View file

@ -34,7 +34,7 @@ ARCHIVE = True
TELEGRAM_TOKEN = ""
MASTODON_TOKEN = ""
MASTODON_URL = ""
ANNOUNCEREPEAT = 4
ANNOUNCEREPEAT = 3
#Scrivi la prima configurazione
configfile = 'playlistalo.conf'
@ -370,8 +370,10 @@ def listtot(res = sys.maxsize):
if announcepos == 0:
if os.path.exists("announce/repeat.mp3"):
plt.append(["announce/repeat.mp3"])
announcepos = (announcepos + 1) % ANNOUNCEREPEAT
announcepos = ANNOUNCEREPEAT - 1
else:
announcepos = (announcepos - 1)
plt.append(x)
return plt[:res]
@ -387,7 +389,7 @@ def getlastannounce():
def setlastannounce(announcepos):
with open("announce/last","w") as f:
f.write(announcepos = (announcepos + 1) % ANNOUNCEREPEAT)
f.write(str(announcepos))
def consume(song):
if os.path.exists(song):
@ -399,16 +401,18 @@ def consume(song):
with open(os.path.dirname(song) + "/last", "w") as f:
f.write(time.strftime("%Y%m%d%H%M%S"))
#resetta il contatore announcelast
setlastannounce(0)
setlastannounce(ANNOUNCEREPEAT)
elif song.split("/")[0] == "fallback":
fname = time.strftime("%Y%m%d%H%M%S") + "|" + "|".join(os.path.basename(song).split("|")[1:])
fname = os.path.dirname(song) + "/" + fname
os.rename(song, fname)
announcepos = getlastannounce()
print("Annuncio da " + str(announcepos) + " a " + str(announcepos - 1))
setlastannounce(announcepos - 1)
elif song.split("/")[0] == "announce":
announcepos = getlastannounce()
setlastannounce(announcepos = (announcepos + 1) % ANNOUNCEREPEAT)
setlastannounce(ANNOUNCEREPEAT)
def addstartannounce():
@ -435,7 +439,7 @@ def plaympd():
looptime = 10
synctime = 5
listlen = 5
listlen = 10
if SHUFFLEUSERS:
shuffleusers()
@ -448,6 +452,8 @@ def plaympd():
#cancella la cartella mpd
if os.path.exists("mpd"):
shutil.rmtree("mpd")
os.makedirs("mpd")
client.rescan()
#aggiunge l'annuncio iniziale
addstartannounce()
@ -466,7 +472,7 @@ def plaympd():
#consuma il primo e fa play
consume(plt[0][0])
client.play()
client.play(0)
while True:
# print("Current")
@ -507,7 +513,8 @@ def plaympd():
def mpdclean(client):
#cancella le precedenti
for x in range(int(client.status()['song'])):
song = client.playlistinfo()[x]['file']
song = client.playlistinfo()[0]['file']
print ("consumo la canzone " + str(x) +" "+ song)
consume(song)
client.delete(0)
#e pulisce anche in mpd
@ -530,6 +537,7 @@ def mpdsync(client, listlen):
print(f[0])
copyfile(f[0], "mpd/" + f[0])
client.rescan()
time.sleep(0.5)
#cancella tutto tranne la prima
for x in client.playlistinfo()[1:]:
client.delete(1)
@ -540,6 +548,22 @@ def mpdsync(client, listlen):
# playlist=client.playlistinfo()
# for f in plt[:len(playlist)-1]:
# i = plt.index(f) + 1
# if f[0] != playlist[i]['file']:
# break
# else:
# print("Mantengo " + f[0])
# #print (i)
# for x in client.playlistinfo()[i+1:]:
# #print("cancello " + client.playlist()[i-1]['file'])
# client.delete(i)
# #e rifa la playlist
# for f in plt[i:]:
# print("Aggiungo " + f[0])
# client.add(f[0])