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
|
|
|
|
2020-11-05 23:53:27 +00:00
|
|
|
class PlanItem:
|
2021-02-14 20:10:32 +00:00
|
|
|
_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
|
2021-02-14 20:10:32 +00:00
|
|
|
def weight(self) -> int:
|
|
|
|
return self._weight
|
2020-12-20 01:10:19 +00:00
|
|
|
|
2021-03-13 22:32:04 +00:00
|
|
|
@weight.setter
|
|
|
|
def weight(self, value: int):
|
|
|
|
self._weight = value
|
|
|
|
|
2020-12-20 01:10:19 +00:00
|
|
|
@property
|
2021-02-14 20:10:32 +00:00
|
|
|
def timeslotitemid(self) -> int:
|
|
|
|
return self._timeslotitemid
|
2020-11-01 02:35:14 +00:00
|
|
|
|
|
|
|
@property
|
2021-02-14 20:10:32 +00:00
|
|
|
def filename(self) -> Optional[str]:
|
2020-11-01 02:35:14 +00:00
|
|
|
return self._filename
|
|
|
|
|
2020-12-08 19:41:11 +00:00
|
|
|
@filename.setter
|
2021-02-14 20:10:32 +00:00
|
|
|
def filename(self, value: Optional[str]):
|
2020-12-08 19:41:11 +00:00
|
|
|
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
|
|
|
|
|
2020-11-05 23:53:27 +00:00
|
|
|
@property
|
2021-02-14 20:10:32 +00:00
|
|
|
def trackid(self) -> Optional[int]:
|
|
|
|
return self._trackid
|
2020-11-05 23:53:27 +00:00
|
|
|
|
2020-11-16 22:49:33 +00:00
|
|
|
@property
|
2021-02-14 20:10:32 +00:00
|
|
|
def managedid(self) -> Optional[int]:
|
|
|
|
return self._managedid
|
2020-11-16 22:49:33 +00:00
|
|
|
|
2020-12-20 01:10:19 +00:00
|
|
|
@property
|
|
|
|
def title(self) -> Optional[str]:
|
|
|
|
return self._title
|
|
|
|
|
|
|
|
@property
|
|
|
|
def artist(self) -> Optional[str]:
|
|
|
|
return self._artist
|
|
|
|
|
2021-02-14 20:10:32 +00:00
|
|
|
@property
|
|
|
|
def length(self) -> Optional[str]:
|
|
|
|
return self._length
|
|
|
|
|
|
|
|
@property
|
|
|
|
def type(self) -> Optional[str]:
|
|
|
|
return "aux" if self.managedid else "central"
|
|
|
|
|
2020-11-03 00:32:43 +00:00
|
|
|
@property
|
2020-12-19 14:57:37 +00:00
|
|
|
def __dict__(self):
|
2020-11-01 02:35:14 +00:00
|
|
|
return {
|
2021-02-14 20:10:32 +00:00
|
|
|
"weight": self.weight,
|
|
|
|
"timeslotitemid": self.timeslotitemid,
|
|
|
|
"trackid": self._trackid,
|
|
|
|
"type": self.type,
|
|
|
|
"managedid": self._managedid,
|
2020-11-03 00:32:43 +00:00
|
|
|
"title": self._title,
|
|
|
|
"artist": self._artist,
|
2020-11-01 02:35:14 +00:00
|
|
|
"name": self.name,
|
2021-02-14 20:10:32 +00:00
|
|
|
"filename": self.filename,
|
|
|
|
"length": self.length
|
2020-11-03 00:32:43 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 14:57:37 +00:00
|
|
|
def __init__(self, new_item: Dict[str, Any]):
|
2021-02-14 20:10:32 +00:00
|
|
|
self._timeslotitemid = new_item["timeslotitemid"]
|
|
|
|
self._managedid = new_item["managedid"] if "managedid" in new_item else None
|
2021-04-06 21:39:33 +00:00
|
|
|
self._trackid = int(new_item["trackid"]) if "trackid" in new_item and not self._managedid else None
|
2021-02-14 20:10:32 +00:00
|
|
|
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.
|
2021-04-06 21:39:33 +00:00
|
|
|
self._weight = int(new_item["weight"])
|
2020-11-03 00:32:43 +00:00
|
|
|
self._title = new_item["title"]
|
2021-02-14 20:10:32 +00:00
|
|
|
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
|
2020-11-16 22:49:33 +00:00
|
|
|
if self.filename:
|
|
|
|
if os.path.sep == "/":
|
|
|
|
self._filename = self.filename.replace("\\", '/')
|
|
|
|
else:
|
|
|
|
self._filename = self.filename.replace("/", '\\')
|