more show plan item stuffs

This commit is contained in:
michael-grace 2020-11-02 23:06:45 +00:00
parent bd0c27ddc3
commit 1e464b2247
2 changed files with 41 additions and 18 deletions

View file

@ -176,6 +176,19 @@ class Player():
self.state.update("show_plan", self.state.state["show_plan"] + [PlanObject(new_item)]) self.state.update("show_plan", self.state.state["show_plan"] + [PlanObject(new_item)])
return True return True
def remove_from_plan(self, timeslotitemid: int) -> bool:
plan_copy = copy.copy(self.state.state["show_plan"])
for i in range(len(plan_copy)):
if plan_copy[i].timeslotitemid == timeslotitemid:
plan_copy.remove(i)
self.state.update("show_plan", plan_copy)
return True
return False
def clear_channel_plan(self) -> bool:
self.state.update("show_plan", [])
return True
def load(self, timeslotitemid: int): def load(self, timeslotitemid: int):
if not self.isPlaying: if not self.isPlaying:
self.unload() self.unload()
@ -330,33 +343,23 @@ class Player():
"PAUSE": lambda: self._retMsg(self.pause()), "PAUSE": lambda: self._retMsg(self.pause()),
"UNPAUSE": lambda: self._retMsg(self.unpause()), "UNPAUSE": lambda: self._retMsg(self.unpause()),
"STOP": lambda: self._retMsg(self.stop()), "STOP": lambda: self._retMsg(self.stop()),
"SEEK": lambda: self._retMsg(self.seek(float(self.last_msg.split(":")[1]))),
"LOAD": lambda: self._retMsg(self.load(int(self.last_msg.split(":")[1]))),
"LOADED?": lambda: self._retMsg(self.isLoaded),
"UNLOAD": lambda: self._retMsg(self.unload()), "UNLOAD": lambda: self._retMsg(self.unload()),
"STATUS": lambda: self._retMsg(self.status, True) "STATUS": lambda: self._retMsg(self.status, True),
"ADD": lambda: self._retMsg(self.add_to_plan(json.loads(":".join(self.last_msg.split(":")[1:])))),
"REMOVE": lambda: self._retMsg(self.remove_from_plan(int(self.last_msg.split(":")[1]))),
"CLEAR": lambda: self._retMsg(self.clear_channel_plan())
} }
if self.last_msg in message_types.keys(): if self.last_msg in message_types.keys():
message_types[self.last_msg]() message_types[self.last_msg]()
elif (self.last_msg == 'LOADED?'):
self._retMsg(self.isLoaded)
continue
elif (self.last_msg.startswith("ADD")):
split = self.last_msg.split(":")
self._retMsg(self.add_to_plan(json.loads(":".join(split[1:]))))
elif (self.last_msg == 'QUIT'): elif (self.last_msg == 'QUIT'):
self.running = False self.running = False
continue continue
elif (self.last_msg.startswith("SEEK")):
split = self.last_msg.split(":")
self._retMsg(self.seek(float(split[1])))
elif (self.last_msg.startswith("LOAD")):
split = self.last_msg.split(":")
self._retMsg(self.load(int(split[1])))
else: else:
self._retMsg("Unknown Command") self._retMsg("Unknown Command")
else: else:

View file

@ -38,6 +38,7 @@ channel_to_q = []
channel_from_q = [] channel_from_q = []
channel_p = [] channel_p = []
### General Endpoints
@app.errorhandler(404) @app.errorhandler(404)
def page_not_found(e): def page_not_found(e):
@ -92,6 +93,7 @@ def ui_status():
} }
return render_template('status.html', data=data) return render_template('status.html', data=data)
### Channel Audio Options
@app.route("/player/<int:channel>/play") @app.route("/player/<int:channel>/play")
def play(channel): def play(channel):
@ -138,6 +140,8 @@ def output(channel, name):
channel_to_q[channel].put("OUTPUT:" + name) channel_to_q[channel].put("OUTPUT:" + name)
return ui_status() return ui_status()
### Channel Items
@app.route("/player/<int:channel>/load/<int:timeslotitemid>") @app.route("/player/<int:channel>/load/<int:timeslotitemid>")
def load(channel:int, timeslotitemid: int): def load(channel:int, timeslotitemid: int):
channel_to_q[channel].put("LOAD:" + str(timeslotitemid)) channel_to_q[channel].put("LOAD:" + str(timeslotitemid))
@ -177,6 +181,15 @@ def remove_plan(channel: int, timeslotitemid: int):
#TODO Return #TODO Return
return True return True
@app.route("/player/<int:channel>/clear")
def clear_channel_plan(channel: int):
channel_to_q[channel].put("CLEAR")
#TODO Return
return True
### General Channel Endpoints
@app.route("/player/<int:channel>/status") @app.route("/player/<int:channel>/status")
def status(channel): def status(channel):
@ -198,7 +211,14 @@ def status(channel):
def all_stop(): def all_stop():
for channel in channel_to_q: for channel in channel_to_q:
channel.put("STOP") channel.put("STOP")
ui_status() return ui_status()
@app.route("/player/all/clear")
def clear_all_channels():
for channel in channel_to_q:
channel.put("CLEAR")
return ui_status()
@app.route('/static/<path:path>') @app.route('/static/<path:path>')