welcome to BAPSicle and some data types
This commit is contained in:
parent
1e464b2247
commit
ec6d3b0854
7 changed files with 54 additions and 22 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -26,4 +26,4 @@ venv/
|
|||
|
||||
config.py
|
||||
|
||||
dev/test.mp3
|
||||
dev/welcome.mp3
|
|
@ -4,3 +4,4 @@ mutagen
|
|||
sounddevice
|
||||
autopep8
|
||||
setproctitle
|
||||
pyttsx3
|
|
@ -1,3 +1,6 @@
|
|||
# Flask Details
|
||||
HOST: str = "localhost"
|
||||
PORT: int = 5000
|
||||
|
||||
# BAPSicle Details
|
||||
VERSION: float = 1.0
|
16
plan.py
16
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
|
||||
}
|
14
player.py
14
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
|
||||
|
|
25
server.py
25
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)
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
Loading…
Reference in a new issue