Add played counting.
This commit is contained in:
parent
23aefe4ba6
commit
ee82fe6d4c
3 changed files with 51 additions and 2 deletions
|
@ -28,6 +28,7 @@ class PlanItem:
|
||||||
_trackid: Optional[int]
|
_trackid: Optional[int]
|
||||||
_managedid: Optional[int]
|
_managedid: Optional[int]
|
||||||
_markers: List[Marker] = []
|
_markers: List[Marker] = []
|
||||||
|
_play_count: int
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def weight(self) -> int:
|
def weight(self) -> int:
|
||||||
|
@ -53,6 +54,19 @@ class PlanItem:
|
||||||
def filename(self, value: Optional[str]):
|
def filename(self, value: Optional[str]):
|
||||||
self._filename = value
|
self._filename = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def play_count(self) -> int:
|
||||||
|
return self._play_count
|
||||||
|
|
||||||
|
def play_count_increment(self):
|
||||||
|
self._play_count += 1
|
||||||
|
|
||||||
|
def play_count_decrement(self):
|
||||||
|
self._play_count = max(0,self._play_count - 1)
|
||||||
|
|
||||||
|
def play_count_reset(self):
|
||||||
|
self._play_count = 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
return (
|
return (
|
||||||
|
@ -129,7 +143,9 @@ class PlanItem:
|
||||||
"intro": self.intro,
|
"intro": self.intro,
|
||||||
"cue": self.cue,
|
"cue": self.cue,
|
||||||
"outro": self.outro,
|
"outro": self.outro,
|
||||||
"markers": self.markers
|
"markers": self.markers,
|
||||||
|
"played": self.play_count > 0,
|
||||||
|
"play_count": self.play_count
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, new_item: Dict[str, Any]):
|
def __init__(self, new_item: Dict[str, Any]):
|
||||||
|
@ -150,6 +166,7 @@ class PlanItem:
|
||||||
self._markers = (
|
self._markers = (
|
||||||
[Marker(marker) for marker in new_item["markers"]] if "markers" in new_item else []
|
[Marker(marker) for marker in new_item["markers"]] if "markers" in new_item else []
|
||||||
)
|
)
|
||||||
|
self._play_count = new_item["play_count"] if "play_count" in new_item else 0
|
||||||
|
|
||||||
# TODO: Edit this to handle markers when MyRadio supports them
|
# TODO: Edit this to handle markers when MyRadio supports them
|
||||||
if "intro" in new_item and (isinstance(new_item["intro"], int) or isinstance(new_item["intro"], float)) and new_item["intro"] > 0:
|
if "intro" in new_item and (isinstance(new_item["intro"], int) or isinstance(new_item["intro"], float)) and new_item["intro"] > 0:
|
||||||
|
|
32
player.py
32
player.py
|
@ -190,7 +190,8 @@ class Player:
|
||||||
|
|
||||||
def unpause(self):
|
def unpause(self):
|
||||||
if not self.isPlaying:
|
if not self.isPlaying:
|
||||||
position: float = self.state.get()["pos_true"]
|
state = self.state.get()
|
||||||
|
position: float = state["pos_true"]
|
||||||
try:
|
try:
|
||||||
self.play(position)
|
self.play(position)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -200,6 +201,13 @@ class Player:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.state.update("paused", False)
|
self.state.update("paused", False)
|
||||||
|
|
||||||
|
# Increment Played count
|
||||||
|
loaded_item = state["loaded_item"]
|
||||||
|
if loaded_item:
|
||||||
|
loaded_item.play_count_increment()
|
||||||
|
self.state.update("loaded_item", loaded_item)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -537,6 +545,20 @@ class Player:
|
||||||
|
|
||||||
return success
|
return success
|
||||||
|
|
||||||
|
def reset_played(self, weight: int):
|
||||||
|
plan: List[PlanItem] = self.state.get()["show_plan"]
|
||||||
|
if weight == -1:
|
||||||
|
for item in plan:
|
||||||
|
item.play_count_reset()
|
||||||
|
self.state.update("show_plan", plan)
|
||||||
|
elif len(plan) > weight:
|
||||||
|
plan[weight].play_count_reset()
|
||||||
|
self.state.update("show_plan", plan[weight], weight)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
|
|
||||||
# This essentially allows the tracklist end API call to happen in a separate thread, to avoid hanging playout/loading.
|
# This essentially allows the tracklist end API call to happen in a separate thread, to avoid hanging playout/loading.
|
||||||
|
@ -565,6 +587,13 @@ class Player:
|
||||||
self.tracklist_start_timer.cancel()
|
self.tracklist_start_timer.cancel()
|
||||||
self.tracklist_start_timer = None
|
self.tracklist_start_timer = None
|
||||||
|
|
||||||
|
# Decrement Played count on track we didn't play much of.
|
||||||
|
state = self.state.get()
|
||||||
|
loaded_item = state["loaded_item"]
|
||||||
|
if loaded_item and loaded_item.type == "central":
|
||||||
|
loaded_item.play_count_decrement()
|
||||||
|
self.state.update("loaded_item", loaded_item)
|
||||||
|
|
||||||
# Make a copy of the tracklist_id, it will get reset as we load the next item.
|
# Make a copy of the tracklist_id, it will get reset as we load the next item.
|
||||||
tracklist_id = self.state.get()["tracklist_id"]
|
tracklist_id = self.state.get()["tracklist_id"]
|
||||||
if not tracklist_id:
|
if not tracklist_id:
|
||||||
|
@ -900,6 +929,7 @@ class Player:
|
||||||
),
|
),
|
||||||
"CLEAR": lambda: self._retMsg(self.clear_channel_plan()),
|
"CLEAR": lambda: self._retMsg(self.clear_channel_plan()),
|
||||||
"SETMARKER": lambda: self._retMsg(self.set_marker(self.last_msg.split(":")[1], self.last_msg.split(":", 2)[2])),
|
"SETMARKER": lambda: self._retMsg(self.set_marker(self.last_msg.split(":")[1], self.last_msg.split(":", 2)[2])),
|
||||||
|
"RESETPLAYED": lambda: self._retMsg(self.reset_played(int(self.last_msg.split(":")[1])))
|
||||||
}
|
}
|
||||||
|
|
||||||
message_type: str = self.last_msg.split(":")[0]
|
message_type: str = self.last_msg.split(":")[0]
|
||||||
|
|
|
@ -144,6 +144,8 @@ class WebsocketServer:
|
||||||
extra += json.dumps(data["newItem"])
|
extra += json.dumps(data["newItem"])
|
||||||
elif command == "REMOVE":
|
elif command == "REMOVE":
|
||||||
extra += str(data["weight"])
|
extra += str(data["weight"])
|
||||||
|
elif command == "RESETPLAYED":
|
||||||
|
extra += str(data["weight"])
|
||||||
elif command == "GET_PLAN":
|
elif command == "GET_PLAN":
|
||||||
extra += str(data["timeslotId"])
|
extra += str(data["timeslotId"])
|
||||||
elif command == "SETMARKER":
|
elif command == "SETMARKER":
|
||||||
|
|
Loading…
Reference in a new issue