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

refactor: play command domain uses

parent 924c9af8
No related branches found
No related tags found
1 merge request!35ORM-less scheduling
......@@ -62,8 +62,6 @@ class TimeslotCommand(EngineExecutor):
Args:
engine (Engine): The engine
timeslot (Timeslot): The timeslot which is starting at this time
TODO refactor
"""
self.config = AuraConfig()
self.engine = engine
......@@ -145,15 +143,14 @@ class PlayCommand(EngineExecutor):
Args:
engine (Engine): The engine
items ([PlaylistItem]): One or more playlist items to be started
TODO refactor
"""
self.config = AuraConfig()
self.engine = engine
preload_offset = self.config.get("preload_offset")
start_preload = items[0].start_unix - preload_offset
start_play = items[0].start_unix
first_item: PlaylistItem = items[0]
start_preload = first_item.get_start() - preload_offset
start_play = first_item.get_start()
msg = (
f"Preloading items at {SU.fmt_time(start_preload)}, {preload_offset} seconds before"
f" playing it at {SU.fmt_time(start_play)}"
......@@ -161,9 +158,9 @@ class PlayCommand(EngineExecutor):
self.logger.info(msg)
# Initialize the "preload" EngineExecuter and attach a child `PlayCommand` to the
# "on_ready" event handler
timeslot_id = items[0].playlist.timeslot.timeslot_id
super().__init__(f"PRELOAD#{timeslot_id}", None, start_preload, self.do_preload, items)
EngineExecutor(f"PLAY#{timeslot_id}", self, start_play, self.do_play, items)
id = first_item.playlist.timeslot.get_id()
super().__init__(f"PRELOAD#{id}", None, start_preload, self.do_preload, items)
EngineExecutor(f"PLAY#{id}", self, start_play, self.do_play, items)
def do_preload(self, items: [PlaylistItem]):
"""
......@@ -176,7 +173,8 @@ class PlayCommand(EngineExecutor):
"""
items_str = ResourceUtil.get_items_string(items)
try:
if items[0].get_content_type() in ResourceClass.FILE.types:
first_item: PlaylistItem = items[0]
if first_item.get_content_type() in ResourceClass.FILE.types:
self.logger.info(SU.cyan(f"=== preload_group('{items_str}') ==="))
self.engine.player.preload_group(items)
else:
......@@ -185,7 +183,8 @@ class PlayCommand(EngineExecutor):
except LoadSourceException as e:
self.logger.critical(SU.red(f"Could not preload items {items_str}"), e)
if items[-1].status != PlaylistItem.PlayStatus.READY:
last_item: PlaylistItem = items[-1]
if last_item.play_status != PlaylistItem.PlayStatus.READY:
msg = f"Items didn't reach 'ready' state during preloading (Items: {items_str})"
self.logger.warning(SU.red(msg))
......@@ -200,16 +199,18 @@ class PlayCommand(EngineExecutor):
"""
items_str = ResourceUtil.get_items_string(items)
self.logger.info(SU.cyan(f"=== play('{items_str}') ==="))
if items[-1].status != PlaylistItem.PlayStatus.READY:
last_item: PlaylistItem = items[-1]
if last_item.play_status != PlaylistItem.PlayStatus.READY:
# Let 'em play anyway ...
msg = f"PLAY: Item(s) not yet ready to be played" f" (Items: {items_str})"
self.logger.critical(SU.red(msg))
while items[-1].status != PlaylistItem.PlayStatus.READY:
while last_item.play_status != PlaylistItem.PlayStatus.READY:
self.logger.info("PLAY: Wait a little bit until preloading is done ...")
time.sleep(2)
self.engine.player.play(items[0], Player.TransitionType.FADE)
self.logger.info(self.engine.scheduler.timetable_renderer.get_ascii_timeslots())
timetable_renderer: utils.TimetableRenderer = self.engine.scheduler.timetable_renderer
self.logger.info(timetable_renderer.get_ascii_timeslots())
#
......@@ -399,6 +400,7 @@ class AuraScheduler(threading.Thread):
if seconds_to_roll > 0:
# Without plenty of timeout (10s) the roll doesn't work
# TODO Check if this is still the case with Liquidsoap 2
# TODO Think if this should be externalized as a command for better testability
def async_preroll(seconds_to_roll):
seconds_to_roll += sleep_offset
time.sleep(sleep_offset)
......
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