diff --git a/README.md b/README.md index 118f498..3928d3f 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Enable verbose logging by passing ``verbose=True`` into the ``API`` object decla #### Channels - Get all channels: ``channels = dtv.channels`` -> list of ``Channel`` objects - Get all channel numbers: ``channel_numbers = dtv.channel_numbers`` -> list of ints -- Get a specific channel: ``channel = dtv.get_channel(channel_number: int)`` -> ``Channel`` object +- Get a specific channel: ``channel = dtv.get_channel(channel_number: int, channel_name: str)`` -> ``Channel`` object - Get brief info on a specific channel: ``channel_info = dtv.get_channel_info(channel_number: int)`` -> ``{"name": str, "number": int, "icon": str}`` - Add a channel: ``new_channel = dtv.add_channel(programs: [Program, PlexAPI Video, ...], plex_server: PlexAPI Server [Optional], handle_errors: bool, **kwargs)`` -> ``Channel`` object - Update a channel: ``updated = dtv.update_channel(channel_number: int, **kwargs)`` or ``Channel.update(**kwargs)`` -> True/False diff --git a/dizqueTV/channels.py b/dizqueTV/channels.py index ec25f30..519e824 100644 --- a/dizqueTV/channels.py +++ b/dizqueTV/channels.py @@ -316,10 +316,10 @@ def __init__(self, for filler_data in data.get('fallback')] self.watermark = Watermark(data=data.get('watermark'), dizque_instance=dizque_instance, - channel_instance=self) + channel_instance=self) if data.get('watermark') else None self.transcoding = ChannelFFMPEGSettings(data=data.get('transcoding'), dizque_instance=dizque_instance, - channel_instance=self) + channel_instance=self) if data.get('transcoding') else None self.schedule = None if data.get('scheduleBackup'): self.schedule = Schedule(data=data.get('scheduleBackup'), diff --git a/dizqueTV/dizquetv.py b/dizqueTV/dizquetv.py index 04c5aed..6a8ef36 100644 --- a/dizqueTV/dizquetv.py +++ b/dizqueTV/dizquetv.py @@ -335,17 +335,25 @@ def channels(self) -> List[Channel]: json_data = self._get_json(endpoint='/channels', timeout=5) # large JSON may take longer, so bigger timeout return [Channel(data=channel, dizque_instance=self) for channel in json_data] - def get_channel(self, channel_number: int) -> Union[Channel, None]: + def get_channel(self, channel_number: int = None, channel_name: str = None) -> Union[Channel, None]: """ - Get a specific dizqueTV channel + Get a specific dizqueTV channel by number or name :param channel_number: Number of channel + :param channel_name: Name of channel :return: Channel object or None :rtype: Channel | None """ - channel_data = self._get_json(endpoint=f'/channel/{channel_number}') - if channel_data: - return Channel(data=channel_data, dizque_instance=self) + if not channel_number and not channel_name: + raise MissingParametersError("Must include either 'channel_number' or 'channel_name'") + if channel_number: + channel_data = self._get_json(endpoint=f'/channel/{channel_number}') + if channel_data: + return Channel(data=channel_data, dizque_instance=self) + if channel_name: + for channel in self.channels: + if channel.name == channel_name: + return channel return None def get_channel_info(self, channel_number: int) -> json: