From 8d9c9884ccdcc5c6c62e69c8d95ae35eed4644cc Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Tue, 27 Oct 2020 21:21:40 +0100 Subject: [PATCH] Assign next timeslot. Docs. #43 #44 --- modules/plugins/trackservice.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/modules/plugins/trackservice.py b/modules/plugins/trackservice.py index 0d3dfa4e..b435f273 100644 --- a/modules/plugins/trackservice.py +++ b/modules/plugins/trackservice.py @@ -64,6 +64,11 @@ class TrackServiceHandler(): def on_queue(self, entries): """ + Items have been queued. They are stored to the local playlog, allowing later + matching and retrieval to augment meta-information. + + Args: + entries ([PlaylistEntry]): The entries which got queued """ for entry in entries: self.playlog.add(entry) @@ -100,6 +105,7 @@ class TrackServiceHandler(): self.store_clock_info(data) + def on_metadata(self, meta): """ Some metadata update was sent from Liquidsoap. @@ -138,7 +144,6 @@ class TrackServiceHandler(): self.store_trackservice(data) self.store_clock_info(data) - def store_trackservice(self, data): @@ -163,8 +168,8 @@ class TrackServiceHandler(): """ current_playlist = self.engine.scheduler.get_active_playlist() (past_timeslot, current_timeslot, next_timeslot) = self.playlog.get_timeslots() - next_timeslot = self.engine.scheduler.get_next_schedules(1) - if next_timeslot: next_timeslot = next_timeslot[0] + # next_timeslot = self.engine.scheduler.get_next_timeslots(1) + # if next_timeslot: next_timeslot = next_timeslot[0] data = dict() data["engine_source"] = self.config.get("api_engine_number") @@ -239,13 +244,21 @@ class Playlog: def set_timeslot(self, timeslot): """ + Sets the current timeslot and proper default values if no timeslot is available. + Any previous timeslot is stored to `self.previous_timeslot` and the following one + to `self.next_timeslot`. + + This method is protect by overwritting by multiple calls with the same timeslot. + + Args: + timeslot (Timeslot): The current timeslot """ if timeslot and self.previous_timeslot: if self.previous_timeslot.get("schedule_start") == timeslot.schedule_start: return # Avoid overwrite by multiple calls in a row data = {} - next_timeslot = self.engine.scheduler.get_next_schedules(1) + next_timeslot = self.engine.scheduler.get_next_timeslots(1) if next_timeslot: next_timeslot = next_timeslot[0] if timeslot: @@ -281,7 +294,7 @@ class Playlog: data["schedule_end"] = datetime.now() + timedelta(hours=1) - if self.next_timeslot: + if next_timeslot: ns = {} self.assign_fallback_playlist(ns, next_timeslot) ns["schedule_id"] = next_timeslot.schedule_id @@ -298,6 +311,11 @@ class Playlog: def assign_fallback_playlist(self, data, timeslot): """ + Assigns fallback info to the given timeslot. + + Args: + data ({}): The dictionary holding the (virtual) timeslot + timeslot (Timeslot): The actual timeslot object to retrieve fallback info from """ fallback_type = None playlist = None @@ -318,6 +336,10 @@ class Playlog: def get_timeslots(self): """ + Retrieves all available timeslots for the past, future and the current one. + + Returns: + ({}, {}, {}) """ return (self.previous_timeslot, self.current_timeslot, self.next_timeslot) -- GitLab