Migrate internal planitem format to match webstudio/api
This commit is contained in:
parent
45d9c32146
commit
4741694d66
4 changed files with 60 additions and 74 deletions
|
@ -71,14 +71,14 @@ class MyRadioAPI():
|
||||||
|
|
||||||
def get_filename(self, item: PlanItem):
|
def get_filename(self, item: PlanItem):
|
||||||
format = "mp3" # TODO: Maybe we want this customisable?
|
format = "mp3" # TODO: Maybe we want this customisable?
|
||||||
if item.trackId:
|
if item.trackid:
|
||||||
itemType = "track"
|
itemType = "track"
|
||||||
id = item.trackId
|
id = item.trackid
|
||||||
url = "/NIPSWeb/secure_play?trackid={}&{}".format(id, format)
|
url = "/NIPSWeb/secure_play?trackid={}&{}".format(id, format)
|
||||||
|
|
||||||
elif item.managedId:
|
elif item.managedid:
|
||||||
itemType = "managed"
|
itemType = "managed"
|
||||||
id = item.managedId
|
id = item.managedid
|
||||||
url = "/NIPSWeb/managed_play?managedid={}".format(id)
|
url = "/NIPSWeb/managed_play?managedid={}".format(id)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
67
plan.py
67
plan.py
|
@ -16,28 +16,28 @@ from typing import Any, Dict, Optional
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class PlanItem:
|
class PlanItem:
|
||||||
_timeslotItemId: int = 0
|
_timeslotitemid: int = 0
|
||||||
_channelWeight: int = 0
|
_weight: int = 0
|
||||||
_filename: str = ""
|
_filename: Optional[str]
|
||||||
_title: str = ""
|
_title: str
|
||||||
_artist: str = ""
|
_artist: Optional[str]
|
||||||
_trackId: Optional[int] = None
|
_trackid: Optional[int]
|
||||||
_managedId: Optional[int] = None
|
_managedid: Optional[int]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def channelWeight(self) -> int:
|
def weight(self) -> int:
|
||||||
return self._channelWeight
|
return self._weight
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timeslotItemId(self) -> int:
|
def timeslotitemid(self) -> int:
|
||||||
return self._timeslotItemId
|
return self._timeslotitemid
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def filename(self) -> str:
|
def filename(self) -> Optional[str]:
|
||||||
return self._filename
|
return self._filename
|
||||||
|
|
||||||
@filename.setter
|
@filename.setter
|
||||||
def filename(self, value: str):
|
def filename(self, value: Optional[str]):
|
||||||
self._filename = value
|
self._filename = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -45,12 +45,12 @@ class PlanItem:
|
||||||
return "{0} - {1}".format(self._title, self._artist) if self._artist else self._title
|
return "{0} - {1}".format(self._title, self._artist) if self._artist else self._title
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def trackId(self) -> Optional[int]:
|
def trackid(self) -> Optional[int]:
|
||||||
return self._trackId
|
return self._trackid
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def managedId(self) -> Optional[int]:
|
def managedid(self) -> Optional[int]:
|
||||||
return self._managedId
|
return self._managedid
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self) -> Optional[str]:
|
def title(self) -> Optional[str]:
|
||||||
|
@ -60,27 +60,38 @@ class PlanItem:
|
||||||
def artist(self) -> Optional[str]:
|
def artist(self) -> Optional[str]:
|
||||||
return self._artist
|
return self._artist
|
||||||
|
|
||||||
|
@property
|
||||||
|
def length(self) -> Optional[str]:
|
||||||
|
return self._length
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self) -> Optional[str]:
|
||||||
|
return "aux" if self.managedid else "central"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __dict__(self):
|
def __dict__(self):
|
||||||
return {
|
return {
|
||||||
"channelWeight": self.channelWeight,
|
"weight": self.weight,
|
||||||
"timeslotItemId": self.timeslotItemId,
|
"timeslotitemid": self.timeslotitemid,
|
||||||
"trackId": self._trackId,
|
"trackid": self._trackid,
|
||||||
"managedId": self._managedId,
|
"type": self.type,
|
||||||
|
"managedid": self._managedid,
|
||||||
"title": self._title,
|
"title": self._title,
|
||||||
"artist": self._artist,
|
"artist": self._artist,
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
"filename": self.filename
|
"filename": self.filename,
|
||||||
|
"length": self.length
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, new_item: Dict[str, Any]):
|
def __init__(self, new_item: Dict[str, Any]):
|
||||||
self._timeslotItemId = new_item["timeslotItemId"]
|
self._timeslotitemid = new_item["timeslotitemid"]
|
||||||
self._trackId = new_item["trackId"] if "trackId" in new_item else None
|
self._managedid = new_item["managedid"] if "managedid" in new_item else None
|
||||||
self._managedId = new_item["managedId"] if "managedId" in new_item else None
|
self._trackid = new_item["trackid"] if "trackid" in new_item and not self._managedid else None
|
||||||
self._filename = new_item["filename"] # This could be a temp dir for API-downloaded items, or a mapped drive.
|
self._filename = new_item["filename"] if "filename" in new_item else None # This could be a temp dir for API-downloaded items, or a mapped drive.
|
||||||
self._channelWeight = new_item["channelWeight"]
|
self._weight = new_item["weight"]
|
||||||
self._title = new_item["title"]
|
self._title = new_item["title"]
|
||||||
self._artist = new_item["artist"]
|
self._artist = new_item["artist"] if "artist" in new_item else None
|
||||||
|
self._length = new_item["length"]
|
||||||
|
|
||||||
# Fix any OS specific / or \'s
|
# Fix any OS specific / or \'s
|
||||||
if self.filename:
|
if self.filename:
|
||||||
|
|
39
player.py
39
player.py
|
@ -142,6 +142,8 @@ class Player():
|
||||||
# Audio Playout Related Methods
|
# Audio Playout Related Methods
|
||||||
|
|
||||||
def play(self, pos: float = 0):
|
def play(self, pos: float = 0):
|
||||||
|
if self.isPlaying or not self.isLoaded:
|
||||||
|
return
|
||||||
global starting
|
global starting
|
||||||
global already_stopped
|
global already_stopped
|
||||||
starting = True
|
starting = True
|
||||||
|
@ -233,18 +235,9 @@ class Player():
|
||||||
if len(plan) > channel:
|
if len(plan) > channel:
|
||||||
for plan_item in plan[str(channel)]:
|
for plan_item in plan[str(channel)]:
|
||||||
try:
|
try:
|
||||||
new_item: Dict[str, any] = {
|
self.add_to_plan(plan_item)
|
||||||
"channelWeight": int(plan_item["weight"]),
|
except Exception as e:
|
||||||
"filename": None,
|
self.logger.log.critical("Failed to add item to show plan: {}".format(e))
|
||||||
"title": plan_item["title"],
|
|
||||||
"artist": plan_item["artist"] if "artist" in plan_item.keys() else None,
|
|
||||||
"timeslotItemId": int(plan_item["timeslotitemid"]) if "timeslotitemid" in plan_item.keys() and plan_item["timeslotitemid"] != None else None,
|
|
||||||
"trackId": int(plan_item["trackid"]) if "managedid" not in plan_item.keys() and plan_item["trackid"] != None else None,
|
|
||||||
"recordId": int(plan_item["trackid"]) if "trackid" in plan_item.keys() and plan_item["trackid"] != None else None, # TODO This is wrong.
|
|
||||||
"managedId": int(plan_item["managedid"]) if "managedid" in plan_item.keys() and plan_item["managedid"] != None else None,
|
|
||||||
}
|
|
||||||
self.add_to_plan(new_item)
|
|
||||||
except:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -254,10 +247,10 @@ class Player():
|
||||||
self.state.update("show_plan", self.state.state["show_plan"] + [PlanItem(new_item)])
|
self.state.update("show_plan", self.state.state["show_plan"] + [PlanItem(new_item)])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def remove_from_plan(self, channel_weight: int) -> bool:
|
def remove_from_plan(self, weight: int) -> bool:
|
||||||
plan_copy: List[PlanItem] = copy.copy(self.state.state["show_plan"])
|
plan_copy: List[PlanItem] = copy.copy(self.state.state["show_plan"])
|
||||||
for i in plan_copy:
|
for i in plan_copy:
|
||||||
if i.channelWeight == channel_weight:
|
if i.weight == weight:
|
||||||
plan_copy.remove(i)
|
plan_copy.remove(i)
|
||||||
self.state.update("show_plan", plan_copy)
|
self.state.update("show_plan", plan_copy)
|
||||||
return True
|
return True
|
||||||
|
@ -267,7 +260,7 @@ class Player():
|
||||||
self.state.update("show_plan", [])
|
self.state.update("show_plan", [])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def load(self, channelWeight: int):
|
def load(self, weight: int):
|
||||||
if not self.isPlaying:
|
if not self.isPlaying:
|
||||||
self.unload()
|
self.unload()
|
||||||
|
|
||||||
|
@ -276,12 +269,12 @@ class Player():
|
||||||
loaded_item: Optional[PlanItem] = None
|
loaded_item: Optional[PlanItem] = None
|
||||||
|
|
||||||
for i in range(len(showplan)):
|
for i in range(len(showplan)):
|
||||||
if showplan[i].channelWeight == channelWeight:
|
if showplan[i].weight == weight:
|
||||||
loaded_item = showplan[i]
|
loaded_item = showplan[i]
|
||||||
break
|
break
|
||||||
|
|
||||||
if loaded_item == None:
|
if loaded_item == None:
|
||||||
self.logger.log.error("Failed to find channelWeight: {}".format(channelWeight))
|
self.logger.log.error("Failed to find weight: {}".format(weight))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if (loaded_item.filename == "" or loaded_item.filename == None):
|
if (loaded_item.filename == "" or loaded_item.filename == None):
|
||||||
|
@ -293,7 +286,7 @@ class Player():
|
||||||
self.state.update("loaded_item", loaded_item)
|
self.state.update("loaded_item", loaded_item)
|
||||||
|
|
||||||
for i in range(len(showplan)):
|
for i in range(len(showplan)):
|
||||||
if showplan[i].channelWeight == channelWeight:
|
if showplan[i].weight == weight:
|
||||||
self.state.update("show_plan", index=i, value=loaded_item)
|
self.state.update("show_plan", index=i, value=loaded_item)
|
||||||
break
|
break
|
||||||
# TODO: Update the show plan filenames
|
# TODO: Update the show plan filenames
|
||||||
|
@ -356,7 +349,7 @@ class Player():
|
||||||
|
|
||||||
loadedItem = self.state.state["loaded_item"]
|
loadedItem = self.state.state["loaded_item"]
|
||||||
if (loadedItem):
|
if (loadedItem):
|
||||||
self.load(loadedItem.channelWeight)
|
self.load(loadedItem.weight)
|
||||||
if wasPlaying:
|
if wasPlaying:
|
||||||
self.unpause()
|
self.unpause()
|
||||||
|
|
||||||
|
@ -401,14 +394,14 @@ class Player():
|
||||||
# Auto Advance
|
# Auto Advance
|
||||||
elif self.state.state["auto_advance"]:
|
elif self.state.state["auto_advance"]:
|
||||||
for i in range(len(self.state.state["show_plan"])):
|
for i in range(len(self.state.state["show_plan"])):
|
||||||
if self.state.state["show_plan"][i].channelWeight == loaded_item.channelWeight:
|
if self.state.state["show_plan"][i].weight == loaded_item.weight:
|
||||||
if len(self.state.state["show_plan"]) > i+1:
|
if len(self.state.state["show_plan"]) > i+1:
|
||||||
self.load(self.state.state["show_plan"][i+1].channelWeight)
|
self.load(self.state.state["show_plan"][i+1].weight)
|
||||||
break
|
break
|
||||||
|
|
||||||
# Repeat All
|
# Repeat All
|
||||||
elif self.state.state["repeat"] == "ALL":
|
elif self.state.state["repeat"] == "ALL":
|
||||||
self.load(self.state.state["show_plan"][0].channelWeight)
|
self.load(self.state.state["show_plan"][0].weight)
|
||||||
|
|
||||||
# Play on Load
|
# Play on Load
|
||||||
if self.state.state["play_on_load"]:
|
if self.state.state["play_on_load"]:
|
||||||
|
@ -498,7 +491,7 @@ class Player():
|
||||||
loaded_item = loaded_state["loaded_item"]
|
loaded_item = loaded_state["loaded_item"]
|
||||||
if loaded_item:
|
if loaded_item:
|
||||||
self.logger.log.info("Loading filename: " + str(loaded_item.filename))
|
self.logger.log.info("Loading filename: " + str(loaded_item.filename))
|
||||||
self.load(loaded_item.channelWeight)
|
self.load(loaded_item.weight)
|
||||||
|
|
||||||
if loaded_state["pos_true"] != 0:
|
if loaded_state["pos_true"] != 0:
|
||||||
self.logger.log.info("Seeking to pos_true: " + str(loaded_state["pos_true"]))
|
self.logger.log.info("Seeking to pos_true: " + str(loaded_state["pos_true"]))
|
||||||
|
|
|
@ -49,26 +49,8 @@ async def websocket_handler(websocket, path):
|
||||||
channel_to_q[channel].put("REPEAT:" + str(data["mode"]).lower())
|
channel_to_q[channel].put("REPEAT:" + str(data["mode"]).lower())
|
||||||
|
|
||||||
|
|
||||||
# Wasteland
|
|
||||||
elif data["command"] == "ADD":
|
elif data["command"] == "ADD":
|
||||||
if "managedId" in data["newItem"].keys() and isinstance(data["newItem"]["managedId"], str):
|
channel_to_q[channel].put("ADD:" + json.dumps(data["newItem"]))
|
||||||
if data["newItem"]["managedId"].startswith("managed"):
|
|
||||||
managed_id = int(data["newItem"]["managedId"].split(":")[1])
|
|
||||||
else:
|
|
||||||
managed_id = int(data["newItem"]["managedId"])
|
|
||||||
else:
|
|
||||||
managed_id = None
|
|
||||||
new_item: Dict[str, any] = {
|
|
||||||
"channelWeight": int(data["newItem"]["weight"]),
|
|
||||||
"filename": None,
|
|
||||||
"title": data["newItem"]["title"],
|
|
||||||
"artist": data["newItem"]["artist"] if "artist" in data["newItem"].keys() else None,
|
|
||||||
"timeslotItemId": int(data["newItem"]["timeslotItemId"]) if "timeslotItemId" in data["newItem"].keys() and data["newItem"]["timeslotItemId"] != None else None,
|
|
||||||
"trackId": int(data["newItem"]["trackId"]) if "trackId" in data["newItem"].keys() and data["newItem"]["trackId"] != None else None,
|
|
||||||
"recordId": int(data["newItem"]["trackId"]) if "trackId" in data["newItem"].keys() and data["newItem"]["trackId"] != None else None,
|
|
||||||
"managedId": managed_id
|
|
||||||
}
|
|
||||||
channel_to_q[channel].put("ADD:" + json.dumps(new_item))
|
|
||||||
elif data["command"] == "REMOVE":
|
elif data["command"] == "REMOVE":
|
||||||
channel_to_q[channel].put("REMOVE:" + str(data["weight"]))
|
channel_to_q[channel].put("REMOVE:" + str(data["weight"]))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue