Skip to content
Snippets Groups Projects
Verified Commit 7ffb1c3c authored by Chris Pastl's avatar Chris Pastl Committed by Ole Binder
Browse files

refactor: adapt fetch_timeslots, fetch_playlist

parent 48fd5ab4
No related branches found
No related tags found
1 merge request!46Steering playout schema and virtual timeslot integration
......@@ -159,23 +159,13 @@ class ApiFetcher(threading.Thread):
@private
"""
api_timeslots = None
url = self.url_api_timeslots
self.logger.debug("Fetch timeslots from Steering API...")
url = self.url_api_timeslots
result = self.api.get(url, params={"includeVirtual": "true"})
api_timeslots = result.json
if not api_timeslots:
return
# FIXME Steering doesn't provide JSON as per a valid JSON schema.
# Hence we need to split the array manually for now.
# @see https://gitlab.servus.at/aura/steering/-/issues/154
# api_timetable: list[API_PLAYOUT_ENTRY] = []
# for entry in api_timeslots:
# api_timeslot = API_PLAYOUT_ENTRY.from_dict(entry)
# if self.is_valid_timeslot(entry):
# api_timetable.append(api_timeslot)
# Transform API timeslots to engine timeslots
timeslots: list[Timeslot] = []
for api_ts in api_timeslots:
......@@ -184,29 +174,28 @@ class ApiFetcher(threading.Thread):
id=api_ts.show.id,
name=api_ts.show.name,
)
# FIXME There is no defined delimiter for multiple entries of following props yet
# For now only a list with one entry is assigned.
episode = Episode(
id=api_ts.episode.id,
title=api_ts.episode.title,
)
episode = Episode(id=ep.id, title=ep.title) if (ep := api_ts.episode) and ep else None
# TODO resolve timeslot referenced by `repetition_id`
timeslot = Timeslot(
id=api_ts.timeslot.id,
repetition_id=api_ts.timeslot.repetition_of_id,
start=api_ts.timeslot.start.timestamp(),
end=api_ts.timeslot.end.timestamp(),
id=api_ts.id,
repetition_id=api_ts.timeslot.repetition_of_id if api_ts.timeslot else None,
start=api_ts.start.timestamp(),
end=api_ts.end.timestamp(),
show=show,
episode=episode,
)
# Fetch playlists for timeslot
playlist_timeslot = self.fetch_playlist(api_ts.timeslot.playlist_id)
playlist_schedule = (
self.fetch_playlist(api_ts.schedule.default_playlist_id)
if api_ts.schedule
else None
)
playlist_show = self.fetch_playlist(api_ts.show.default_playlist_id)
playlist_timeslot = None
playlist_schedule = None
playlist_show = None
if (ts := api_ts.timeslot) and ts and (plid := ts.playlist_id) and plid:
playlist_timeslot = self.fetch_playlist(plid)
if (sc := api_ts.schedule) and sc and (plid := sc.default_playlist_id) and plid:
playlist_schedule = self.fetch_playlist(plid)
if (sh := api_ts.show) and sh and (plid := sh.default_playlist_id):
playlist_show = self.fetch_playlist(plid)
timeslot.set_playlists(playlist_timeslot, playlist_schedule, playlist_show)
self.expand_item_duration(playlist_timeslot)
self.expand_item_duration(playlist_schedule)
......@@ -233,11 +222,11 @@ class ApiFetcher(threading.Thread):
playlist: Playlist = None
url = self.url_api_playlist.replace("${ID}", str(playlist_id))
self.logger.debug("Fetch playlist from Tank API...")
self.logger.debug(f"Fetch playlist '{playlist_id}' from Tank API...")
result = self.api.get(url, headers=self.tank_headers)
SU.log_json(self.logger, result.json)
api_playlist = API_PLAYLIST.from_dict(result.json)
if api_playlist:
try:
api_playlist = API_PLAYLIST.from_dict(result.json)
playlist = Playlist(
api_playlist.id, api_playlist.description, api_playlist.playout_mode != "linear"
)
......@@ -266,6 +255,9 @@ class ApiFetcher(threading.Thread):
for i in items:
playlist.add(i)
except Exception as e:
self.logger.error(SU.red(f"Decode API_PLAYLIST failed: {e}"))
return playlist
@private
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment