From 7f27fa6e7e305fa4441e2a578a6084b8dffc7194 Mon Sep 17 00:00:00 2001 From: nharris Date: Wed, 21 Sep 2022 19:17:42 -0600 Subject: [PATCH] - Account for empty program data when making a channel --- dizqueTV/dizquetv.py | 14 +++++++------- dizqueTV/models/channels.py | 6 ++++-- dizqueTV/models/guide.py | 10 ++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dizqueTV/dizquetv.py b/dizqueTV/dizquetv.py index 1e9b61e..a0c5061 100644 --- a/dizqueTV/dizquetv.py +++ b/dizqueTV/dizquetv.py @@ -694,7 +694,7 @@ def _fill_in_default_channel_settings( :return: Dictionary of settings with defaults filled in :rtype: dict """ - if not settings_dict.get("programs"): # empty or doesn't exist + if not settings_dict.get("programs", []): # empty or doesn't exist if handle_errors: settings_dict["programs"] = [{"duration": 600000, "isOffline": True}] else: @@ -724,7 +724,7 @@ def _fill_in_default_channel_settings( ] = f"{self.url}/images/generic-offline-screen.png" # override duration regardless of user input settings_dict["duration"] = sum( - program["duration"] for program in settings_dict["programs"] + program["duration"] for program in settings_dict.get("programs", []) ) settings_dict["watermark"] = fill_in_watermark_settings(**settings_dict) return helpers._combine_settings_add_new( @@ -852,9 +852,9 @@ def _make_schedule( if res: schedule_json = res.json() return channel.update( - programs=schedule_json["programs"], - startTime=schedule_json["startTime"], - scheduleBackup=data["schedule"], + programs=schedule_json.get("programs", []), + startTime=schedule_json.get("startTime", ""), + scheduleBackup=data.get("schedule", {}), ) return False @@ -1600,8 +1600,8 @@ def create_custom_show_with_programs( return CustomShow(data=custom_show_data, dizque_instance=self) def parse_custom_shows_and_non_custom_shows( - self, items: list, non_custom_show_type, **kwargs - ): + self, items: List, non_custom_show_type, **kwargs + ) -> List[Union[Program, CustomShow]]: custom_show_programs = [] current_custom_show_id = None parsing_custom_show = False diff --git a/dizqueTV/models/channels.py b/dizqueTV/models/channels.py index 7d7824f..3e2f3ea 100644 --- a/dizqueTV/models/channels.py +++ b/dizqueTV/models/channels.py @@ -335,7 +335,7 @@ def delete(self) -> bool: class Channel(BaseAPIObject): def __init__(self, data: dict, dizque_instance, plex_server: PServer = None): super().__init__(data, dizque_instance) - self._program_data = data.get("programs") + self._program_data = data.get("programs", []) self._fillerCollections_data = data.get("fillerCollections") self.fillerRepeatCooldown = data.get("fillerRepeatCooldown") self.startTime = data.get("startTime") @@ -592,8 +592,10 @@ def add_program( ignore_keys=["_id", "id"], ): channel_data = self._data - if not channel_data["duration"]: + if not channel_data.get("duration"): channel_data["duration"] = 0 + if not channel_data.get("programs", []): + channel_data["programs"] = [] channel_data["programs"].append(kwargs) channel_data["duration"] += kwargs.get("duration", 0) return self.update(**channel_data) diff --git a/dizqueTV/models/guide.py b/dizqueTV/models/guide.py index 4859ebd..7f2715c 100644 --- a/dizqueTV/models/guide.py +++ b/dizqueTV/models/guide.py @@ -49,12 +49,10 @@ def get_lineup(self, from_date: datetime, to_date: datetime) -> List[GuideProgra json_data = self._dizque_instance._get_json( endpoint=f"/guide/channels/{self.number}", params=params ) - if json_data.get("programs"): - return [ + return [ GuideProgram(data=program_data) - for program_data in json_data["programs"] + for program_data in json_data.get("programs", []) ] - return [] class Guide(BaseAPIObject): @@ -75,10 +73,10 @@ def _create_channels_and_programs(self) -> List[GuideChannel]: channels = [] for channel_number, data in self._data.items(): programs = [ - GuideProgram(data=program_data) for program_data in data["programs"] + GuideProgram(data=program_data) for program_data in data.get("programs", []) ] channel = GuideChannel( - data=data["channel"], + data=data.get("channel", {}), programs=programs, dizque_instance=self._dizque_instance, )