Add new bool option to get_stream method

This commit is contained in:
samedamci 2021-09-11 21:06:48 +02:00
parent 70458c4136
commit 5e1a07e793
No known key found for this signature in database
GPG Key ID: FCB4A9A20D00E894
2 changed files with 8 additions and 6 deletions

View File

@ -55,8 +55,12 @@ 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 get_stream(self, program: Program) -> 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:
ts_end = program.ts_stop
else:
ts_end = now_timestamp() - 60000 * 3 # 3 minutes ago
params = { params = {
"channelKey": program.channel, "channelKey": program.channel,
@ -65,7 +69,7 @@ class MatteBOX:
"subscriptionCode": self.subscription_code, "subscriptionCode": self.subscription_code,
"deviceType": "STB", "deviceType": "STB",
"fromTimestamp": program.ts_start, "fromTimestamp": program.ts_start,
"toTimestamp": program.ts_stop, "toTimestamp": ts_end,
} }
res = self.__get("/sws/server/streaming/uris.json", params=params) res = self.__get("/sws/server/streaming/uris.json", params=params)

View File

@ -1,5 +1,4 @@
from __future__ import annotations from __future__ import annotations
from .helpers import now_timestamp
class Program: class Program:
@ -8,7 +7,7 @@ class Program:
content_id: str content_id: str
description: str description: str
ts_start: int ts_start: int
ts_stop: int ts_stop: int = None
type: str type: str
@classmethod @classmethod
@ -20,7 +19,7 @@ class Program:
"content_id": data["epgId"], "content_id": data["epgId"],
"description": data["shortDescription"], "description": data["shortDescription"],
"ts_start": data["startTimestamp"], "ts_start": data["startTimestamp"],
"ts_stop": now_timestamp() - 60000 * 3, # 3 minutes ago "ts_stop": data["endTimestamp"],
"type": "program", "type": "program",
} }
return obj return obj
@ -34,7 +33,6 @@ class Program:
"content_id": data["pvrProgramId"], "content_id": data["pvrProgramId"],
"description": data["longDescription"], "description": data["longDescription"],
"ts_start": data["startTime"], "ts_start": data["startTime"],
"ts_stop": now_timestamp(),
"type": "recording", "type": "recording",
} }
return obj return obj