Add add_recording method and exceptions

This commit is contained in:
samedamci 2021-09-16 18:12:42 +02:00
parent 5e1a07e793
commit 55f1f41db3
No known key found for this signature in database
GPG Key ID: FCB4A9A20D00E894
3 changed files with 25 additions and 1 deletions

View File

@ -1,11 +1,13 @@
import requests import requests
import json import json
import m3u8 import m3u8
from urllib3.exceptions import HTTPError
from typing import List from typing import List
from .auth import login from .auth import login
from .consts import API from .consts import API
from .helpers import now_timestamp from .helpers import now_timestamp
from .types import Program from .types import Program
from .exceptions import RecordingException
class MatteBOX: class MatteBOX:
@ -55,6 +57,15 @@ class MatteBOX:
recordings = [Program.from_recording(r) for r in res["entities"]] recordings = [Program.from_recording(r) for r in res["entities"]]
return recordings 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: def get_stream(self, program: Program, end: bool = True) -> str:
service_type = "TIMESHIFT_TV" if program.type == "program" else "NPVR" service_type = "TIMESHIFT_TV" if program.type == "program" else "NPVR"
if end: if end:

10
mattebox/exceptions.py Normal file
View File

@ -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

View File

@ -4,6 +4,7 @@ from __future__ import annotations
class Program: class Program:
name: str name: str
channel: str channel: str
epg_id: str
content_id: str content_id: str
description: str description: str
ts_start: int ts_start: int
@ -16,7 +17,8 @@ class Program:
obj.__dict__ = { obj.__dict__ = {
"name": data["name"], "name": data["name"],
"channel": data["channelKey"], "channel": data["channelKey"],
"content_id": data["epgId"], "epg_id": data["epgId"],
"content_id": obj.epg_id,
"description": data["shortDescription"], "description": data["shortDescription"],
"ts_start": data["startTimestamp"], "ts_start": data["startTimestamp"],
"ts_stop": data["endTimestamp"], "ts_stop": data["endTimestamp"],
@ -30,6 +32,7 @@ class Program:
obj.__dict__ = { obj.__dict__ = {
"name": data["title"], "name": data["title"],
"channel": data["channelKey"], "channel": data["channelKey"],
"epg_id": data["epgId"],
"content_id": data["pvrProgramId"], "content_id": data["pvrProgramId"],
"description": data["longDescription"], "description": data["longDescription"],
"ts_start": data["startTime"], "ts_start": data["startTime"],