Skip to content
Snippets Groups Projects
Commit 5d76d8b6 authored by David Trattnig's avatar David Trattnig
Browse files

Diff between playlist and playlog. engine-clock#2

parent 4abd4d26
No related branches found
No related tags found
No related merge requests found
Pipeline #890 passed
...@@ -133,7 +133,7 @@ class TrackServiceHandler(): ...@@ -133,7 +133,7 @@ class TrackServiceHandler():
duration = float(meta.get("duration")) duration = float(meta.get("duration"))
data["track_duration"] = int(duration) data["track_duration"] = int(duration)
else: else:
data["track_duration"] = 0 data["track_duration"] = 0
entry = self.playlog.resolve_entry(meta["filename"]) entry = self.playlog.resolve_entry(meta["filename"])
...@@ -146,9 +146,10 @@ class TrackServiceHandler(): ...@@ -146,9 +146,10 @@ class TrackServiceHandler():
data["show_name"] = entry.playlist.timeslot.show_name data["show_name"] = entry.playlist.timeslot.show_name
else: else:
# This is a fallback playlog which wasn't scheduled actually (e.g. station fallback) # 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: if timeslot:
data = {**data, **timeslot} data = {**data, **timeslot}
data["playlist_id"] = -1
data["log_source"] = self.config.get("api_engine_number") data["log_source"] = self.config.get("api_engine_number")
data = SU.clean_dictionary(data) data = SU.clean_dictionary(data)
...@@ -167,6 +168,7 @@ class TrackServiceHandler(): ...@@ -167,6 +168,7 @@ class TrackServiceHandler():
url = self.config.get("api_engine_store_playlog") url = self.config.get("api_engine_store_playlog")
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
body = json.dumps(data, indent=4, sort_keys=True, default=str) 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) response = requests.post(url, data=body, headers=headers)
if response.status_code != 204 or response.status_code != 204: 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" msg = f"Error while posting playlog to Engine API: {response.reason} (Error {response.status_code})\n"
...@@ -177,35 +179,35 @@ class TrackServiceHandler(): ...@@ -177,35 +179,35 @@ class TrackServiceHandler():
""" """
Posts the current and next show information to the Engine API. Posts the current and next show information to the Engine API.
""" """
current_playlist = None planned_playlist = None
if self.engine.scheduler: 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() (past_timeslot, current_timeslot, next_timeslot) = self.playlog.get_timeslots()
data = dict() data = dict()
data["engine_source"] = self.config.get("api_engine_number") data["engine_source"] = self.config.get("api_engine_number")
if current_playlist: if current_timeslot:
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["current_timeslot"] = 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: if next_timeslot:
data["next_timeslot"] = next_timeslot data["next_timeslot"] = next_timeslot
...@@ -216,6 +218,7 @@ class TrackServiceHandler(): ...@@ -216,6 +218,7 @@ class TrackServiceHandler():
url = self.config.get("api_engine_store_clock") url = self.config.get("api_engine_store_clock")
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
body = json.dumps(data, indent=4, sort_keys=True, default=str) 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) response = requests.put(url, data=body, headers=headers)
if response.status_code != 204 or response.status_code != 204: 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" msg = f"Error while posting clock-info to Engine API: {response.reason} (Error {response.status_code})\n"
...@@ -226,7 +229,7 @@ class TrackServiceHandler(): ...@@ -226,7 +229,7 @@ class TrackServiceHandler():
class Playlog: 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. 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 It also is in charge of resolving relevant meta information of the currently playing entry for
the TrackService handler. the TrackService handler.
...@@ -250,7 +253,7 @@ class Playlog: ...@@ -250,7 +253,7 @@ class Playlog:
self.config = AuraConfig.config() self.config = AuraConfig.config()
self.logger = logging.getLogger("AuraEngine") self.logger = logging.getLogger("AuraEngine")
self.engine = engine self.engine = engine
self.history = deque([None, None, None]) self.history = deque(maxlen=100)
self.current_timeslot = {} self.current_timeslot = {}
self.init_timeslot(None) self.init_timeslot(None)
...@@ -269,17 +272,17 @@ class Playlog: ...@@ -269,17 +272,17 @@ class Playlog:
if self.previous_timeslot: if self.previous_timeslot:
data["timeslot_start"] = self.previous_timeslot.get("timeslot_end") data["timeslot_start"] = self.previous_timeslot.get("timeslot_end")
else: else:
data["timeslot_start"] = datetime.now() data["timeslot_start"] = None
if next_timeslot: if next_timeslot:
data["timeslot_end"] = next_timeslot.timeslot_start data["timeslot_end"] = next_timeslot.timeslot_start
else: else:
# Fake the end, because the timeslot is actually not existing data["timeslot_end"] = None
data["timeslot_end"] = datetime.now() + timedelta(hours=1)
self.current_timeslot = data self.current_timeslot = data
def set_timeslot(self, timeslot): def set_timeslot(self, timeslot):
""" """
Sets the current timeslot and proper default values if no timeslot is available. Sets the current timeslot and proper default values if no timeslot is available.
...@@ -376,8 +379,7 @@ class Playlog: ...@@ -376,8 +379,7 @@ class Playlog:
""" """
Saves the currently preloaded [`Entry`] to the local cache. Saves the currently preloaded [`Entry`] to the local cache.
""" """
self.history.pop() self.history.append(entry)
self.history.appendleft(entry)
def get_recent_entries(self): def get_recent_entries(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment