From c524dc62a78a29e80cfec4f9d8153cd77a6479ba Mon Sep 17 00:00:00 2001 From: Rudolf Offereins Date: Wed, 4 Feb 2026 09:34:25 +0000 Subject: [PATCH] Set mediatype --- lghorizon/__init__.py | 2 ++ lghorizon/lghorizon_device_state_processor.py | 19 ++++++++++++--- lghorizon/lghorizon_models.py | 24 +++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lghorizon/__init__.py b/lghorizon/__init__.py index a6753d0..12f73df 100644 --- a/lghorizon/__init__.py +++ b/lghorizon/__init__.py @@ -27,6 +27,7 @@ LGHorizonUIState, LGHorizonProfileOptions, LGHorizonServicesConfig, + LGHorizonMediaType, ) from .exceptions import ( LGHorizonApiError, @@ -70,5 +71,6 @@ "LGHorizonServicesConfig", "LGHorizonRecording", "LGHorizonShowRecordingList", + "LGHorizonMediaType", "COUNTRY_SETTINGS", ] diff --git a/lghorizon/lghorizon_device_state_processor.py b/lghorizon/lghorizon_device_state_processor.py index 081c172..bd0d0d8 100644 --- a/lghorizon/lghorizon_device_state_processor.py +++ b/lghorizon/lghorizon_device_state_processor.py @@ -19,6 +19,7 @@ LGHorizonNDVRSource, LGHorizonReviewBufferSource, LGHorizonRecordingSource, + LGHorizonMediaType, ) from .lghorizon_models import LGHorizonAuth from .lghorizon_models import LGHorizonReplayEvent, LGHorizonVOD, LGHorizonVODType @@ -124,6 +125,7 @@ async def _process_apps_state( device_state.show_title = apps_state.app_name device_state.image = apps_state.logo_path device_state.ui_state_type = LGHorizonUIStateType.APPS + device_state.media_type = LGHorizonMediaType.APP async def _process_linear_state( self, @@ -145,8 +147,10 @@ async def _process_linear_state( service_path, ) replay_event = LGHorizonReplayEvent(event_json) - device_state.id = replay_event.event_id channel = self._channels[replay_event.channel_id] + + device_state.media_type = LGHorizonMediaType.CHANNEL + device_state.id = replay_event.event_id device_state.source_type = source.source_type device_state.channel_id = channel.id device_state.channel_name = channel.title @@ -189,8 +193,10 @@ async def _process_reviewbuffer_state( service_path, ) replay_event = LGHorizonReplayEvent(event_json) - device_state.id = replay_event.event_id channel = self._channels[replay_event.channel_id] + + device_state.media_type = LGHorizonMediaType.CHANNEL + device_state.id = replay_event.event_id device_state.source_type = source.source_type device_state.channel_id = channel.id device_state.channel_name = channel.title @@ -205,6 +211,7 @@ async def _process_reviewbuffer_state( device_state.start_time = replay_event.start_time device_state.end_time = replay_event.end_time device_state.duration = replay_event.end_time - replay_event.start_time + # Add random number to url to force refresh join_param = "?" if join_param in channel.stream_image: @@ -234,9 +241,11 @@ async def _process_replay_state( service_path, ) replay_event = LGHorizonReplayEvent(event_json) - device_state.id = replay_event.event_id # Iets met buffer doen channel = self._channels[replay_event.channel_id] + + device_state.media_type = LGHorizonMediaType.CHANNEL + device_state.id = replay_event.event_id device_state.source_type = source.source_type device_state.channel_id = channel.id device_state.episode_title = replay_event.episode_name @@ -279,8 +288,10 @@ async def _process_vod_state( device_state.episode_title = vod.title device_state.season_number = vod.season device_state.episode_number = vod.episode + device_state.media_type = LGHorizonMediaType.EPISODE else: device_state.show_title = vod.title + device_state.media_type = LGHorizonMediaType.MOVIE device_state.duration = vod.duration device_state.last_position_update = int(time.time()) @@ -335,6 +346,8 @@ async def _process_ndvr_state( else: device_state.show_title = recording.show_title + device_state.media_type = LGHorizonMediaType.CHANNEL + device_state.image = await self._get_intent_image_url(recording.id) async def _get_intent_image_url(self, intent_id: str) -> Optional[str]: diff --git a/lghorizon/lghorizon_models.py b/lghorizon/lghorizon_models.py index 4c85ac1..4f4c2b2 100644 --- a/lghorizon/lghorizon_models.py +++ b/lghorizon/lghorizon_models.py @@ -69,6 +69,17 @@ class LGHorizonUIStateType(Enum): UNKNOWN = "unknown" +class LGHorizonMediaType(Enum): + """Enumeration of LG Horizon Media types""" + + UNKNOWN = "unknown" + CHANNEL = "channel" + APP = "app" + MOVIE = "movie" + EPISODE = "episode" + TVSHOW = "tvshow" + + class LGHorizonMessage(ABC): """Abstract base class for LG Horizon messages.""" @@ -869,6 +880,7 @@ class LGHorizonDeviceState: _speed: Optional[int] _start_time: Optional[int] _end_time: Optional[int] + _media_type: LGHorizonMediaType def __init__(self) -> None: """Initialize the playing info.""" @@ -890,6 +902,7 @@ def __init__(self) -> None: self._id = None self._start_time = None self._end_time = None + self._media_type = LGHorizonMediaType.UNKNOWN @property def state(self) -> LGHorizonRunningState: @@ -1031,6 +1044,16 @@ def ui_state_type(self, value: LGHorizonUIStateType) -> None: """Set the source type.""" self._ui_state_type = value + @property + def media_type(self) -> LGHorizonMediaType: + """Return the source type.""" + return self._media_type + + @media_type.setter + def media_type(self, value: LGHorizonMediaType) -> None: + """Set the source type.""" + self._media_type = value + @property def paused(self) -> bool: """Return if the media is paused.""" @@ -1099,6 +1122,7 @@ async def reset(self) -> None: self.id = None self.start_time = None self.end_time = None + self.media_type = LGHorizonMediaType.UNKNOWN await self.reset_progress()