refactor(playout): unwrap schedule.media dict
This commit is contained in:
parent
0d4e2823e2
commit
00648b8f94
|
@ -18,6 +18,7 @@ from ..config import CACHE_DIR, POLL_INTERVAL, Config
|
||||||
from ..liquidsoap.client import LiquidsoapClient
|
from ..liquidsoap.client import LiquidsoapClient
|
||||||
from ..liquidsoap.models import Info, StreamPreferences, StreamState
|
from ..liquidsoap.models import Info, StreamPreferences, StreamState
|
||||||
from ..timeout import ls_timeout
|
from ..timeout import ls_timeout
|
||||||
|
from .events import Events
|
||||||
from .liquidsoap import PypoLiquidsoap
|
from .liquidsoap import PypoLiquidsoap
|
||||||
from .schedule import get_schedule
|
from .schedule import get_schedule
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ class PypoFetch(Thread):
|
||||||
self.cache_dir = CACHE_DIR
|
self.cache_dir = CACHE_DIR
|
||||||
logger.debug("Cache dir %s", self.cache_dir)
|
logger.debug("Cache dir %s", self.cache_dir)
|
||||||
|
|
||||||
self.schedule_data = []
|
self.schedule_data: Events = {}
|
||||||
logger.info("PypoFetch: init complete")
|
logger.info("PypoFetch: init complete")
|
||||||
|
|
||||||
# Handle a message from RabbitMQ, put it into our yucky global var.
|
# Handle a message from RabbitMQ, put it into our yucky global var.
|
||||||
|
@ -75,7 +76,7 @@ class PypoFetch(Thread):
|
||||||
logger.info("Handling command: %s", command)
|
logger.info("Handling command: %s", command)
|
||||||
|
|
||||||
if command == "update_schedule":
|
if command == "update_schedule":
|
||||||
self.schedule_data = m["schedule"]
|
self.schedule_data = m["schedule"]["media"]
|
||||||
self.process_schedule(self.schedule_data)
|
self.process_schedule(self.schedule_data)
|
||||||
elif command == "reset_liquidsoap_bootstrap":
|
elif command == "reset_liquidsoap_bootstrap":
|
||||||
self.set_bootstrap_variables()
|
self.set_bootstrap_variables()
|
||||||
|
@ -196,10 +197,10 @@ class PypoFetch(Thread):
|
||||||
# to the cache dir (Folder-structure: cache/YYYY-MM-DD-hh-mm-ss)
|
# to the cache dir (Folder-structure: cache/YYYY-MM-DD-hh-mm-ss)
|
||||||
# - runs the cleanup routine, to get rid of unused cached files
|
# - runs the cleanup routine, to get rid of unused cached files
|
||||||
|
|
||||||
def process_schedule(self, schedule_data):
|
def process_schedule(self, events: Events):
|
||||||
self.last_update_schedule_timestamp = time.time()
|
self.last_update_schedule_timestamp = time.time()
|
||||||
logger.debug(schedule_data)
|
logger.debug(events)
|
||||||
media = schedule_data["media"]
|
media = events
|
||||||
media_filtered = {}
|
media_filtered = {}
|
||||||
|
|
||||||
# Download all the media and put playlists in liquidsoap "annotate" format
|
# Download all the media and put playlists in liquidsoap "annotate" format
|
||||||
|
|
|
@ -32,7 +32,7 @@ def insert_event(events: Events, event_key: str, event: AnyEvent):
|
||||||
events[key] = event
|
events[key] = event
|
||||||
|
|
||||||
|
|
||||||
def get_schedule(api_client: ApiClient) -> Dict[Literal["media"], Events]:
|
def get_schedule(api_client: ApiClient) -> Events:
|
||||||
stream_preferences = StreamPreferences(**api_client.get_stream_preferences().json())
|
stream_preferences = StreamPreferences(**api_client.get_stream_preferences().json())
|
||||||
|
|
||||||
current_time = datetime.utcnow()
|
current_time = datetime.utcnow()
|
||||||
|
@ -75,7 +75,7 @@ def get_schedule(api_client: ApiClient) -> Dict[Literal["media"], Events]:
|
||||||
webstream = api_client.get_webstream(item["stream"]).json()
|
webstream = api_client.get_webstream(item["stream"]).json()
|
||||||
generate_webstream_events(events, item, webstream, show)
|
generate_webstream_events(events, item, webstream, show)
|
||||||
|
|
||||||
return {"media": dict(sorted(events.items()))}
|
return dict(sorted(events.items()))
|
||||||
|
|
||||||
|
|
||||||
def generate_live_events(
|
def generate_live_events(
|
||||||
|
|
|
@ -412,7 +412,6 @@ def test_get_schedule(schedule, requests_mock, api_client: ApiClient):
|
||||||
requests_mock.get(f"{base_url}/api/v2/webstreams/1", json=WEBSTREAM_1)
|
requests_mock.get(f"{base_url}/api/v2/webstreams/1", json=WEBSTREAM_1)
|
||||||
|
|
||||||
assert get_schedule(api_client) == {
|
assert get_schedule(api_client) == {
|
||||||
"media": {
|
|
||||||
"2022-09-05-11-00-00": {
|
"2022-09-05-11-00-00": {
|
||||||
"type": EventKind.FILE,
|
"type": EventKind.FILE,
|
||||||
"row_id": 1,
|
"row_id": 1,
|
||||||
|
@ -639,4 +638,3 @@ def test_get_schedule(schedule, requests_mock, api_client: ApiClient):
|
||||||
"filesize": 10000,
|
"filesize": 10000,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue