diff --git a/mattebox/app.py b/mattebox/app.py index 603e9d8..5c12424 100644 --- a/mattebox/app.py +++ b/mattebox/app.py @@ -1,11 +1,13 @@ import requests import json import m3u8 +from urllib3.exceptions import HTTPError from typing import List from .auth import login from .consts import API from .helpers import now_timestamp from .types import Program +from .exceptions import RecordingException class MatteBOX: @@ -55,6 +57,15 @@ class MatteBOX: recordings = [Program.from_recording(r) for r in res["entities"]] return recordings + def add_recording(self, program: Program) -> None: + try: + self.__get( + "/sws/subscription/vod/pvr-add-program.json", + params={"epgId": program.epg_id} + ) + except HTTPError as e: + raise RecordingException(e) from None + def get_stream(self, program: Program, end: bool = True) -> str: service_type = "TIMESHIFT_TV" if program.type == "program" else "NPVR" if end: diff --git a/mattebox/exceptions.py b/mattebox/exceptions.py new file mode 100644 index 0000000..6396722 --- /dev/null +++ b/mattebox/exceptions.py @@ -0,0 +1,10 @@ +import json + + +class MatteBOXException(Exception): + def __init__(self, e: Exception) -> None: + super().__init__(json.loads(str(e))["errorMessage"]) + + +class RecordingException(MatteBOXException): + pass diff --git a/mattebox/types.py b/mattebox/types.py index a5adcd9..314ca66 100644 --- a/mattebox/types.py +++ b/mattebox/types.py @@ -4,6 +4,7 @@ from __future__ import annotations class Program: name: str channel: str + epg_id: str content_id: str description: str ts_start: int @@ -16,7 +17,8 @@ class Program: obj.__dict__ = { "name": data["name"], "channel": data["channelKey"], - "content_id": data["epgId"], + "epg_id": data["epgId"], + "content_id": obj.epg_id, "description": data["shortDescription"], "ts_start": data["startTimestamp"], "ts_stop": data["endTimestamp"], @@ -30,6 +32,7 @@ class Program: obj.__dict__ = { "name": data["title"], "channel": data["channelKey"], + "epg_id": data["epgId"], "content_id": data["pvrProgramId"], "description": data["longDescription"], "ts_start": data["startTime"],