From ec6d3b08549e3967073feb685c67c031cef67580 Mon Sep 17 00:00:00 2001 From: michael-grace Date: Tue, 3 Nov 2020 00:32:43 +0000 Subject: [PATCH] welcome to BAPSicle and some data types --- .gitignore | 2 +- build/requirements.txt | 3 ++- config.py.example | 5 ++++- plan.py | 18 +++++++++++------- player.py | 14 ++++++++------ server.py | 25 +++++++++++++++++++++---- state_manager.py | 9 +++++++-- 7 files changed, 54 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index a528655..f7daaed 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,4 @@ venv/ config.py -dev/test.mp3 \ No newline at end of file +dev/welcome.mp3 \ No newline at end of file diff --git a/build/requirements.txt b/build/requirements.txt index 95b5aa9..6f7f474 100644 --- a/build/requirements.txt +++ b/build/requirements.txt @@ -3,4 +3,5 @@ flask mutagen sounddevice autopep8 -setproctitle \ No newline at end of file +setproctitle +pyttsx3 \ No newline at end of file diff --git a/config.py.example b/config.py.example index 6f3739a..b595413 100644 --- a/config.py.example +++ b/config.py.example @@ -1,3 +1,6 @@ # Flask Details HOST: str = "localhost" -PORT: int = 5000 \ No newline at end of file +PORT: int = 5000 + +# BAPSicle Details +VERSION: float = 1.0 \ No newline at end of file diff --git a/plan.py b/plan.py index 45b2525..072bc34 100644 --- a/plan.py +++ b/plan.py @@ -32,15 +32,19 @@ class PlanObject: def name(self) -> str: return "{0} - {1}".format(self._title, self._artist) if self._artist else self._title + @property + def __dict__(self) -> Dict[str, any]: + return { + "timeslotitemid": self.timeslotitemid, + "title": self._title, + "artist": self._artist, + "name": self.name, + "filename": self.filename + } + def __init__(self, new_item: Dict[str, any]): self._timeslotitemid = new_item["timeslotitemid"] self._filename = new_item["filename"] self._title = new_item["title"] self._artist = new_item["artist"] - - def __dict__(self) -> Dict[str, any]: - return { - "timeslotitemid": self.timeslotitemid, - "name": self.name, - "filename": self.filename - } \ No newline at end of file + \ No newline at end of file diff --git a/player.py b/player.py index a987aea..00134f8 100644 --- a/player.py +++ b/player.py @@ -108,8 +108,8 @@ class Player(): state = copy.copy(self.state.state) # Not the biggest fan of this, but maybe I'll get a better solution for this later - state["loaded_item"] = state["loaded_item"].__dict__() if state["loaded_item"] else None - state["show_plan"] = [repr.__dict__() for repr in state["show_plan"]] + state["loaded_item"] = state["loaded_item"].__dict__ if state["loaded_item"] else None + state["show_plan"] = [repr.__dict__ for repr in state["show_plan"]] res = json.dumps(state) return res @@ -304,8 +304,8 @@ class Player(): self.output() if loaded_state["loaded_item"]: - print("Loading filename: " + loaded_state["loaded_item"["filename"]]) - self.load(loaded_state["loaded_item"["timeslotitemid"]]) + print("Loading filename: " + loaded_state["loaded_item"].filename) + self.load(loaded_state["loaded_item"].timeslotitemid) if loaded_state["pos_true"] != 0: print("Seeking to pos_true: " + str(loaded_state["pos_true"])) @@ -353,8 +353,10 @@ class Player(): "CLEAR": lambda: self._retMsg(self.clear_channel_plan()) } - if self.last_msg in message_types.keys(): - message_types[self.last_msg]() + message_type: str = self.last_msg.split(":")[0] + + if message_type in message_types.keys(): + message_types[message_type]() elif (self.last_msg == 'QUIT'): self.running = False diff --git a/server.py b/server.py index 54e43ae..9181e66 100644 --- a/server.py +++ b/server.py @@ -20,6 +20,7 @@ import json import sounddevice as sd import setproctitle import config +import pyttsx3 setproctitle.setproctitle("BAPSicle - Server") @@ -239,15 +240,31 @@ def startServer(): ) channel_p[channel].start() - # There is a plan for this, but I'm going to leave this here until i sort it + # Welcome Speech + + text_to_speach = pyttsx3.init() + text_to_speach.save_to_file( + """Thank-you for installing BAPSicle - the play-out server from the broadcasting and presenting suite. + This server is accepting connections on port {0} + The version of the server service is {1} + Please refer to the documentation included with this application for further assistance.""".format( + config.PORT, + config.VERSION + ), + "dev/welcome.mp3" + ) + text_to_speach.runAndWait() + new_item: Dict[str, any] = { "timeslotitemid": 0, - "filename": "dev/test.mp3", - "title": "Test File", - "artist": None, + "filename": "dev/welcome.mp3", + "title": "Welcome to BAPSicle", + "artist": "University Radio York", } channel_to_q[0].put("ADD:" + json.dumps(new_item)) + channel_to_q[0].put("LOAD:0") + channel_to_q[0].put("PLAY") # Don't use reloader, it causes Nested Processes! app.run(host=config.HOST, port=config.PORT, debug=True, use_reloader=False) diff --git a/state_manager.py b/state_manager.py index 4d965a5..4992501 100644 --- a/state_manager.py +++ b/state_manager.py @@ -2,6 +2,7 @@ import copy import json import os from helpers.os_environment import resolve_external_file_path +from plan import PlanObject class StateManager: @@ -35,6 +36,10 @@ class StateManager: else: self.__state = json.loads(file_state) + # Turn from JSON -> PlanObject + self.__state["loaded_item"] = PlanObject(self.__state["loaded_item"]) if self.__state["loaded_item"] else None + self.__state["show_plan"] = [PlanObject(obj) for obj in self.__state["show_plan"]] + @property def state(self): return self.__state @@ -47,8 +52,8 @@ class StateManager: # Not the biggest fan of this, but maybe I'll get a better solution for this later state_to_json = copy.copy(state) - state_to_json["loaded_item"] = state_to_json["loaded_item"].__dict__() if state_to_json["loaded_item"] else None - state_to_json["show_plan"] = [repr.__dict__() for repr in state_to_json["show_plan"]] + state_to_json["loaded_item"] = state_to_json["loaded_item"].__dict__ if state_to_json["loaded_item"] else None + state_to_json["show_plan"] = [repr.__dict__ for repr in state_to_json["show_plan"]] file.write(json.dumps(state_to_json, indent=2, sort_keys=True))