From cd0d9b6f4a47105afd9b71df4fc601e2134cfe5b Mon Sep 17 00:00:00 2001 From: jo Date: Sun, 19 Feb 2023 17:56:01 +0100 Subject: [PATCH] refactor(playout): rename event kinds enums --- playout/libretime_playout/player/events.py | 10 +++---- .../libretime_playout/player/liquidsoap.py | 14 +++++----- playout/libretime_playout/player/schedule.py | 12 ++++----- playout/tests/player/schedule_test.py | 26 +++++++++---------- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/playout/libretime_playout/player/events.py b/playout/libretime_playout/player/events.py index 9ce8d42d2..996d3ebc8 100644 --- a/playout/libretime_playout/player/events.py +++ b/playout/libretime_playout/player/events.py @@ -3,8 +3,8 @@ from enum import Enum class EventKind(str, Enum): FILE = "file" - EVENT = "event" - STREAM_BUFFER_START = "stream_buffer_start" - STREAM_OUTPUT_START = "stream_output_start" - STREAM_BUFFER_END = "stream_buffer_end" - STREAM_OUTPUT_END = "stream_output_end" + ACTION = "event" + WEB_STREAM_BUFFER_START = "stream_buffer_start" + WEB_STREAM_OUTPUT_START = "stream_output_start" + WEB_STREAM_BUFFER_END = "stream_buffer_end" + WEB_STREAM_OUTPUT_END = "stream_output_end" diff --git a/playout/libretime_playout/player/liquidsoap.py b/playout/libretime_playout/player/liquidsoap.py index 10c212fe9..f15d704ba 100644 --- a/playout/libretime_playout/player/liquidsoap.py +++ b/playout/libretime_playout/player/liquidsoap.py @@ -28,11 +28,11 @@ class PypoLiquidsoap: def play(self, media_item): if media_item["type"] == EventKind.FILE: self.handle_file_type(media_item) - elif media_item["type"] == EventKind.EVENT: + elif media_item["type"] == EventKind.ACTION: self.handle_event_type(media_item) - elif media_item["type"] == EventKind.STREAM_BUFFER_START: + elif media_item["type"] == EventKind.WEB_STREAM_BUFFER_START: self.telnet_liquidsoap.start_web_stream_buffer(media_item) - elif media_item["type"] == EventKind.STREAM_OUTPUT_START: + elif media_item["type"] == EventKind.WEB_STREAM_OUTPUT_START: if ( media_item["row_id"] != self.telnet_liquidsoap.current_prebuffering_stream_id @@ -41,9 +41,9 @@ class PypoLiquidsoap: # so that the prebuffering stage could take effect. Let's do the prebuffering now. self.telnet_liquidsoap.start_web_stream_buffer(media_item) self.telnet_liquidsoap.start_web_stream(media_item) - elif media_item["type"] == EventKind.STREAM_BUFFER_END: + elif media_item["type"] == EventKind.WEB_STREAM_BUFFER_END: self.telnet_liquidsoap.stop_web_stream_buffer() - elif media_item["type"] == EventKind.STREAM_OUTPUT_END: + elif media_item["type"] == EventKind.WEB_STREAM_OUTPUT_END: self.telnet_liquidsoap.stop_web_stream_output() else: raise UnknownMediaItemType(str(media_item)) @@ -126,7 +126,9 @@ class PypoLiquidsoap: ] scheduled_now_webstream = [ - x for x in scheduled_now if x["type"] in (EventKind.STREAM_OUTPUT_START) + x + for x in scheduled_now + if x["type"] in (EventKind.WEB_STREAM_OUTPUT_START) ] schedule_ids = {x["row_id"] for x in scheduled_now_files} diff --git a/playout/libretime_playout/player/schedule.py b/playout/libretime_playout/player/schedule.py index 88f334fd2..8c93abb4c 100644 --- a/playout/libretime_playout/player/schedule.py +++ b/playout/libretime_playout/player/schedule.py @@ -91,7 +91,7 @@ def generate_live_events( # If enabled, fade the input source out if switch_off_event_key != kick_out_event_key: switch_off_event = { - "type": EventKind.EVENT, + "type": EventKind.ACTION, "event_type": "switch_off", "start": switch_off_event_key, "end": switch_off_event_key, @@ -100,7 +100,7 @@ def generate_live_events( # Then kick the source out kick_out_event = { - "type": EventKind.EVENT, + "type": EventKind.ACTION, "event_type": "kick_out", "start": kick_out_event_key, "end": kick_out_event_key, @@ -158,7 +158,7 @@ def generate_webstream_events( schedule_end_event_key = datetime_to_event_key(schedule["ends_at"]) stream_buffer_start_event = { - "type": EventKind.STREAM_BUFFER_START, + "type": EventKind.WEB_STREAM_BUFFER_START, "row_id": schedule["id"], "start": datetime_to_event_key(schedule["starts_at"] - timedelta(seconds=5)), "end": datetime_to_event_key(schedule["starts_at"] - timedelta(seconds=5)), @@ -168,7 +168,7 @@ def generate_webstream_events( insert_event(events, schedule_start_event_key, stream_buffer_start_event) stream_output_start_event = { - "type": EventKind.STREAM_OUTPUT_START, + "type": EventKind.WEB_STREAM_OUTPUT_START, "row_id": schedule["id"], "start": schedule_start_event_key, "end": schedule_end_event_key, @@ -182,7 +182,7 @@ def generate_webstream_events( # NOTE: stream_*_end were previously triggered 1 second before # the schedule end. stream_buffer_end_event = { - "type": EventKind.STREAM_BUFFER_END, + "type": EventKind.WEB_STREAM_BUFFER_END, "row_id": schedule["id"], "start": schedule_end_event_key, "end": schedule_end_event_key, @@ -192,7 +192,7 @@ def generate_webstream_events( insert_event(events, schedule_end_event_key, stream_buffer_end_event) stream_output_end_event = { - "type": EventKind.STREAM_OUTPUT_END, + "type": EventKind.WEB_STREAM_OUTPUT_END, "row_id": schedule["id"], "start": schedule_end_event_key, "end": schedule_end_event_key, diff --git a/playout/tests/player/schedule_test.py b/playout/tests/player/schedule_test.py index ffd86e7a0..eca1549f3 100644 --- a/playout/tests/player/schedule_test.py +++ b/playout/tests/player/schedule_test.py @@ -275,7 +275,7 @@ def test_generate_live_events(): generate_live_events(result, show_instance_3, 0.0) assert result == { "2022-09-05-13-00-00": { - "type": EventKind.EVENT, + "type": EventKind.ACTION, "event_type": "kick_out", "start": "2022-09-05-13-00-00", "end": "2022-09-05-13-00-00", @@ -286,13 +286,13 @@ def test_generate_live_events(): generate_live_events(result, show_instance_3, 2.0) assert result == { "2022-09-05-12-59-58": { - "type": EventKind.EVENT, + "type": EventKind.ACTION, "event_type": "switch_off", "start": "2022-09-05-12-59-58", "end": "2022-09-05-12-59-58", }, "2022-09-05-13-00-00": { - "type": EventKind.EVENT, + "type": EventKind.ACTION, "event_type": "kick_out", "start": "2022-09-05-13-00-00", "end": "2022-09-05-13-00-00", @@ -340,7 +340,7 @@ def test_generate_webstream_events(): generate_webstream_events(result, schedule_5, WEBSTREAM_1, SHOW_3) assert result == { "2022-09-05-12-10-00": { - "type": EventKind.STREAM_BUFFER_START, + "type": EventKind.WEB_STREAM_BUFFER_START, "row_id": 5, "start": "2022-09-05-12-09-55", "end": "2022-09-05-12-09-55", @@ -348,7 +348,7 @@ def test_generate_webstream_events(): "id": 1, }, "2022-09-05-12-10-00_0": { - "type": EventKind.STREAM_OUTPUT_START, + "type": EventKind.WEB_STREAM_OUTPUT_START, "row_id": 5, "start": "2022-09-05-12-10-00", "end": "2022-09-05-12-40-00", @@ -357,7 +357,7 @@ def test_generate_webstream_events(): "show_name": "Show 3", }, "2022-09-05-12-40-00": { - "type": EventKind.STREAM_BUFFER_END, + "type": EventKind.WEB_STREAM_BUFFER_END, "row_id": 5, "start": "2022-09-05-12-40-00", "end": "2022-09-05-12-40-00", @@ -365,7 +365,7 @@ def test_generate_webstream_events(): "id": 1, }, "2022-09-05-12-40-00_0": { - "type": EventKind.STREAM_OUTPUT_END, + "type": EventKind.WEB_STREAM_OUTPUT_END, "row_id": 5, "start": "2022-09-05-12-40-00", "end": "2022-09-05-12-40-00", @@ -494,7 +494,7 @@ def test_get_schedule(schedule, requests_mock, api_client: ApiClient): "filesize": 10000, }, "2022-09-05-12-10-00": { - "type": EventKind.STREAM_BUFFER_START, + "type": EventKind.WEB_STREAM_BUFFER_START, "row_id": 5, "start": "2022-09-05-12-09-55", "end": "2022-09-05-12-09-55", @@ -502,7 +502,7 @@ def test_get_schedule(schedule, requests_mock, api_client: ApiClient): "id": 1, }, "2022-09-05-12-10-00_0": { - "type": EventKind.STREAM_OUTPUT_START, + "type": EventKind.WEB_STREAM_OUTPUT_START, "row_id": 5, "start": "2022-09-05-12-10-00", "end": "2022-09-05-12-40-00", @@ -511,7 +511,7 @@ def test_get_schedule(schedule, requests_mock, api_client: ApiClient): "show_name": "Show 3", }, "2022-09-05-12-40-00": { - "type": EventKind.STREAM_BUFFER_END, + "type": EventKind.WEB_STREAM_BUFFER_END, "row_id": 5, "start": "2022-09-05-12-40-00", "end": "2022-09-05-12-40-00", @@ -519,7 +519,7 @@ def test_get_schedule(schedule, requests_mock, api_client: ApiClient): "id": 1, }, "2022-09-05-12-40-00_0": { - "type": EventKind.STREAM_OUTPUT_END, + "type": EventKind.WEB_STREAM_OUTPUT_END, "row_id": 5, "start": "2022-09-05-12-40-00", "end": "2022-09-05-12-40-00", @@ -587,13 +587,13 @@ def test_get_schedule(schedule, requests_mock, api_client: ApiClient): "filesize": 10000, }, "2022-09-05-12-59-58": { - "type": EventKind.EVENT, + "type": EventKind.ACTION, "event_type": "switch_off", "start": "2022-09-05-12-59-58", "end": "2022-09-05-12-59-58", }, "2022-09-05-13-00-00": { - "type": EventKind.EVENT, + "type": EventKind.ACTION, "event_type": "kick_out", "start": "2022-09-05-13-00-00", "end": "2022-09-05-13-00-00",