From 7e99da7fc81cf9d70cd706b5a1f96e7611519191 Mon Sep 17 00:00:00 2001 From: Adrian <52701496+futzu@users.noreply.github.com> Date: Sun, 20 Aug 2023 03:51:00 +0000 Subject: [PATCH] added Stream.load() --- threefive/stream.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/threefive/stream.py b/threefive/stream.py index 53fc7ae5..190f306c 100644 --- a/threefive/stream.py +++ b/threefive/stream.py @@ -147,10 +147,9 @@ def __init__(self, tsdata, show_null=True): strm.decode() """ - if isinstance(tsdata, str): - self._tsdata = reader(tsdata) - else: - self._tsdata = tsdata + self._tsdata = None + self.tsdata=tsdata + # self.load(tsdata) self.show_null = show_null self.start = {} self.info = None @@ -162,12 +161,22 @@ def __init__(self, tsdata, show_null=True): def __repr__(self): return str(self.__dict__) + def load(self,tsdata=None): + if not tsdata: + tsdata = self.tsdata + if isinstance(tsdata, str): + self._tsdata = reader(tsdata) + else: + self._tsdata = tsdata + + def _find_start(self): """ _find_start locates the first SYNC_BYTE parses 1 packet and returns a iterator of packets """ + self.load() while self._tsdata: one = self._tsdata.read(1) if not one: @@ -242,6 +251,7 @@ def decode_fu(self, func=show_cue): Super Fast with pypy3. """ num_pkts = 1000 + self.load() for chunk in self.iter_pkts(num_pkts): _ = [func(cue) for cue in self._mk_pkts(chunk) if cue] del _ @@ -289,6 +299,7 @@ def show(self): displays streams that will be parsed for SCTE-35. """ + self.load() self.info = True for pkt in self._find_start(): self._parse_info(pkt)