radio-bullshit/next_song.py

30 lines
931 B
Python
Raw Normal View History

2021-06-05 22:34:59 +00:00
#!/usr/bin/python3
import random, glob, os, json
if __name__ == "__main__":
songs_folder = "/songs"
jingles_folder = "/jingles"
2021-06-05 22:34:59 +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
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:
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"
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"
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
with open(f"{songs_folder}/state.json", "w") as f:
2021-06-05 22:44:09 +00:00
json.dump(state, f, indent=4)