2021-06-05 22:34:59 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import random, glob, os, json
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2021-06-12 10:09:04 +00:00
|
|
|
songs_folder = "/songs"
|
|
|
|
jingles_folder = "/jingles"
|
2021-06-05 22:34:59 +00:00
|
|
|
|
2021-06-12 10:09:04 +00:00
|
|
|
if not os.path.isfile(f"{songs_folder}/state.json"):
|
2021-06-05 22:34:59 +00:00
|
|
|
# create state file if it doesnt exist
|
2021-06-12 10:09:04 +00:00
|
|
|
with open(f"{songs_folder}/state.json", "w") as f:
|
2021-06-05 22:34:59 +00:00
|
|
|
state = {"current_song_type": "jingle"}
|
|
|
|
json.dump(state, f, indent=4)
|
|
|
|
else:
|
2021-06-12 10:09:04 +00:00
|
|
|
with open(f"{songs_folder}/state.json") as f:
|
2021-06-05 22:34:59 +00:00
|
|
|
state = json.load(f)
|
|
|
|
|
|
|
|
if state["current_song_type"] == "song":
|
|
|
|
state["current_song_type"] = "jingle"
|
2021-06-12 10:09:04 +00:00
|
|
|
print(random.choice(glob.glob(f"{jingles_folder}/*.ogg")))
|
2021-06-05 22:34:59 +00:00
|
|
|
elif state["current_song_type"] == "jingle":
|
|
|
|
state["current_song_type"] = "song"
|
2021-06-12 10:09:04 +00:00
|
|
|
print(random.choice(glob.glob(f"{songs_folder}/*.ogg")))
|
2021-06-05 22:34:59 +00:00
|
|
|
else:
|
|
|
|
exit(1)
|
2021-06-05 22:44:09 +00:00
|
|
|
|
2021-06-12 10:09:04 +00:00
|
|
|
with open(f"{songs_folder}/state.json", "w") as f:
|
2021-06-05 22:44:09 +00:00
|
|
|
json.dump(state, f, indent=4)
|