diff --git a/src/plugins/trackservice.py b/src/plugins/trackservice.py index 42354f251f7d336e6aff0a335c91f6f61a0ae9c3..a9730e7a264600370164c3858337370c5f7b8af2 100644 --- a/src/plugins/trackservice.py +++ b/src/plugins/trackservice.py @@ -133,7 +133,7 @@ class TrackServiceHandler(): duration = float(meta.get("duration")) data["track_duration"] = int(duration) else: - data["track_duration"] = 0 + data["track_duration"] = 0 entry = self.playlog.resolve_entry(meta["filename"]) @@ -146,9 +146,10 @@ class TrackServiceHandler(): data["show_name"] = entry.playlist.timeslot.show_name else: # This is a fallback playlog which wasn't scheduled actually (e.g. station fallback) - (past, timeslot, next) = self.playlog.get_timeslots() + (past, timeslot, next) = self.playlog.get_timeslots() if timeslot: - data = {**data, **timeslot} + data = {**data, **timeslot} + data["playlist_id"] = -1 data["log_source"] = self.config.get("api_engine_number") data = SU.clean_dictionary(data) @@ -167,6 +168,7 @@ class TrackServiceHandler(): url = self.config.get("api_engine_store_playlog") headers = {'content-type': 'application/json'} body = json.dumps(data, indent=4, sort_keys=True, default=str) + self.logger.debug("Playlog Data: " + body) response = requests.post(url, data=body, headers=headers) if response.status_code != 204 or response.status_code != 204: msg = f"Error while posting playlog to Engine API: {response.reason} (Error {response.status_code})\n" @@ -177,35 +179,35 @@ class TrackServiceHandler(): """ Posts the current and next show information to the Engine API. """ - current_playlist = None + planned_playlist = None if self.engine.scheduler: - (fallback_type, current_playlist) = self.engine.scheduler.get_active_playlist() + (fallback_type, planned_playlist) = self.engine.scheduler.get_active_playlist() (past_timeslot, current_timeslot, next_timeslot) = self.playlog.get_timeslots() data = dict() - data["engine_source"] = self.config.get("api_engine_number") - - if current_playlist: - data["current_playlist"] = dict() - data["current_playlist"]["playlist_id"] = current_playlist.playlist_id - data["current_playlist"]["entries"] = [] - for e in current_playlist.entries: - entry = dict() - entry["track_start"] = e.entry_start - if e.meta_data: - entry["track_artist"] = e.meta_data.artist - entry["track_album"] = e.meta_data.album - entry["track_title"] = e.meta_data.title - entry["track_num"] = e.entry_num - entry["track_duration"] = e.duration - content_class = ResourceUtil.get_content_class(e.get_content_type()) - entry["track_type"] = content_class.numeric - entry = SU.clean_dictionary(entry) - data["current_playlist"]["entries"].append(entry) - - if current_timeslot: + data["engine_source"] = self.config.get("api_engine_number") + + if current_timeslot: data["current_timeslot"] = current_timeslot + if planned_playlist: + data["planned_playlist"] = dict() + data["planned_playlist"]["playlist_id"] = planned_playlist.playlist_id + data["planned_playlist"]["entries"] = [] + for e in planned_playlist.entries: + entry = dict() + entry["track_start"] = e.entry_start + if e.meta_data: + entry["track_artist"] = e.meta_data.artist + entry["track_album"] = e.meta_data.album + entry["track_title"] = e.meta_data.title + entry["track_num"] = e.entry_num + entry["track_duration"] = e.duration + content_class = ResourceUtil.get_content_class(e.get_content_type()) + entry["track_type"] = content_class.numeric + entry = SU.clean_dictionary(entry) + data["planned_playlist"]["entries"].append(entry) + if next_timeslot: data["next_timeslot"] = next_timeslot @@ -216,6 +218,7 @@ class TrackServiceHandler(): url = self.config.get("api_engine_store_clock") headers = {'content-type': 'application/json'} body = json.dumps(data, indent=4, sort_keys=True, default=str) + self.logger.debug("Clock Data: " + body) response = requests.put(url, data=body, headers=headers) if response.status_code != 204 or response.status_code != 204: msg = f"Error while posting clock-info to Engine API: {response.reason} (Error {response.status_code})\n" @@ -226,7 +229,7 @@ class TrackServiceHandler(): class Playlog: """ - Playlog keeps a short history of currently playing entries. It stores the recent + Playlog keeps a history of currently queued (and playing) entries. It stores the recent active entries to a local cache `history` being able to manage concurrently playing entries. It also is in charge of resolving relevant meta information of the currently playing entry for the TrackService handler. @@ -250,7 +253,7 @@ class Playlog: self.config = AuraConfig.config() self.logger = logging.getLogger("AuraEngine") self.engine = engine - self.history = deque([None, None, None]) + self.history = deque(maxlen=100) self.current_timeslot = {} self.init_timeslot(None) @@ -269,17 +272,17 @@ class Playlog: if self.previous_timeslot: data["timeslot_start"] = self.previous_timeslot.get("timeslot_end") else: - data["timeslot_start"] = datetime.now() + data["timeslot_start"] = None if next_timeslot: data["timeslot_end"] = next_timeslot.timeslot_start - else: - # Fake the end, because the timeslot is actually not existing - data["timeslot_end"] = datetime.now() + timedelta(hours=1) + else: + data["timeslot_end"] = None self.current_timeslot = data + def set_timeslot(self, timeslot): """ Sets the current timeslot and proper default values if no timeslot is available. @@ -376,8 +379,7 @@ class Playlog: """ Saves the currently preloaded [`Entry`] to the local cache. """ - self.history.pop() - self.history.appendleft(entry) + self.history.append(entry) def get_recent_entries(self):