BAPSicle/plan.py

106 lines
2.8 KiB
Python
Raw Normal View History

2020-11-01 02:35:14 +00:00
"""
BAPSicle Server
Next-gen audio playout server for University Radio York playout,
based on WebStudio interface.
Show Plan Items
Authors:
Michael Grace
Date:
November 2020
"""
2020-12-19 14:57:37 +00:00
from typing import Any, Dict, Optional
2020-11-04 00:09:42 +00:00
import os
2020-11-01 02:35:14 +00:00
class PlanItem:
_timeslotitemid: int = 0
_weight: int = 0
_filename: Optional[str]
_title: str
_artist: Optional[str]
_trackid: Optional[int]
_managedid: Optional[int]
2020-11-01 02:35:14 +00:00
@property
def weight(self) -> int:
return self._weight
2021-03-13 22:32:04 +00:00
@weight.setter
def weight(self, value: int):
self._weight = value
@property
def timeslotitemid(self) -> int:
return self._timeslotitemid
2020-11-01 02:35:14 +00:00
@property
def filename(self) -> Optional[str]:
2020-11-01 02:35:14 +00:00
return self._filename
@filename.setter
def filename(self, value: Optional[str]):
self._filename = value
2020-11-01 02:35:14 +00:00
@property
def name(self) -> str:
return "{0} - {1}".format(self._title, self._artist) if self._artist else self._title
@property
def trackid(self) -> Optional[int]:
return self._trackid
@property
def managedid(self) -> Optional[int]:
return self._managedid
@property
def title(self) -> Optional[str]:
return self._title
@property
def artist(self) -> Optional[str]:
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
2020-12-19 14:57:37 +00:00
def __dict__(self):
2020-11-01 02:35:14 +00:00
return {
"weight": self.weight,
"timeslotitemid": self.timeslotitemid,
"trackid": self._trackid,
"type": self.type,
"managedid": self._managedid,
"title": self._title,
"artist": self._artist,
2020-11-01 02:35:14 +00:00
"name": self.name,
"filename": self.filename,
"length": self.length
}
2020-12-19 14:57:37 +00:00
def __init__(self, new_item: Dict[str, Any]):
self._timeslotitemid = new_item["timeslotitemid"]
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"] if "filename" in new_item else None # This could be a temp dir for API-downloaded items, or a mapped drive.
self._weight = new_item["weight"]
self._title = new_item["title"]
self._artist = new_item["artist"] if "artist" in new_item else None
self._length = new_item["length"]
2020-11-04 00:09:42 +00:00
# Fix any OS specific / or \'s
if self.filename:
if os.path.sep == "/":
self._filename = self.filename.replace("\\", '/')
else:
self._filename = self.filename.replace("/", '\\')