2021-09-08 16:17:37 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
class Program:
|
2021-09-16 18:33:39 +02:00
|
|
|
"""Class for single TV program or recording with basic information about it.
|
|
|
|
|
2021-09-18 19:41:15 +02:00
|
|
|
Methods `from_channel_program`, `from_recording` and `from_search_result` returns
|
|
|
|
class object from data received from API."""
|
2021-09-16 18:33:39 +02:00
|
|
|
|
2021-09-08 16:17:37 +02:00
|
|
|
name: str
|
|
|
|
channel: str
|
2021-09-16 18:12:42 +02:00
|
|
|
epg_id: str
|
2021-09-08 16:17:37 +02:00
|
|
|
content_id: str
|
|
|
|
description: str
|
|
|
|
ts_start: int
|
2021-09-11 21:06:48 +02:00
|
|
|
ts_stop: int = None
|
2021-09-08 16:17:37 +02:00
|
|
|
type: str
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_channel_program(cls, data: dict) -> Program:
|
|
|
|
obj = cls()
|
|
|
|
obj.__dict__ = {
|
|
|
|
"name": data["name"],
|
|
|
|
"channel": data["channelKey"],
|
2021-09-16 18:12:42 +02:00
|
|
|
"epg_id": data["epgId"],
|
2021-09-16 19:07:05 +02:00
|
|
|
"content_id": data["epgId"],
|
2021-09-08 16:17:37 +02:00
|
|
|
"description": data["shortDescription"],
|
|
|
|
"ts_start": data["startTimestamp"],
|
2021-09-11 21:06:48 +02:00
|
|
|
"ts_stop": data["endTimestamp"],
|
2021-09-08 16:17:37 +02:00
|
|
|
"type": "program",
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_recording(cls, data: dict) -> Program:
|
|
|
|
obj = cls()
|
|
|
|
obj.__dict__ = {
|
|
|
|
"name": data["title"],
|
|
|
|
"channel": data["channelKey"],
|
2021-09-16 18:12:42 +02:00
|
|
|
"epg_id": data["epgId"],
|
2021-09-08 16:17:37 +02:00
|
|
|
"content_id": data["pvrProgramId"],
|
|
|
|
"description": data["longDescription"],
|
|
|
|
"ts_start": data["startTime"],
|
|
|
|
"type": "recording",
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
|
2021-09-18 19:41:15 +02:00
|
|
|
@classmethod
|
|
|
|
def from_search_result(cls, data: dict) -> Program:
|
|
|
|
obj = cls()
|
|
|
|
obj.__dict__ = {
|
|
|
|
"name": data["name"],
|
|
|
|
"channel": data["channelKey"],
|
|
|
|
"epg_id": data["id"],
|
|
|
|
"content_id": data["id"],
|
|
|
|
"description": data["description"],
|
|
|
|
"ts_start": data["startTimestamp"],
|
|
|
|
"ts_stop": data["endTimestamp"],
|
|
|
|
"type": "program"
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
|
2021-09-08 16:17:37 +02:00
|
|
|
def __repr__(self) -> str:
|
|
|
|
return f"{self.__class__.__name__}({self.__dict__})"
|