futzu/threefive

Cannot create TimeSignal with pts 0

Closed this issue · 2 comments

>>> import threefive
>>> c = threefive.Cue()
>>> c.command = threefive.TimeSignal()
>>> c.command.time_specified_flag = True
>>> c.command.pts_time = 0.0
>>> c.encode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/davide/work/oss/scte35-threefive/threefive/cue.py", line 235, in encode
    cmd_bites = self.command.encode()
                ^^^^^^^^^^^^^^^^^^^^^
  File "/home/davide/work/oss/scte35-threefive/threefive/commands.py", line 128, in encode
    self._encode_splice_time(nbin)
  File "/home/davide/work/oss/scte35-threefive/threefive/commands.py", line 151, in _encode_splice_time
    raise ValueError("\033[7mA float for pts_time for the splice command is required.\033[27m"
ValueError: A float for pts_time for the splice command is required.

I assume pts_time needs to be tested against None rather than for falsiness.

change _encode_splice_time in commands to this

 def _encode_splice_time(self, nbin):
        """
        _encode_splice_time Table 14 - splice_time()
        """
        self._chk_var(bool, nbin.add_flag, "time_specified_flag", 1)
        if self.time_specified_flag:
            nbin.reserve(6)
            if not isinstance(self.pts_time,float):
                raise ValueError("\033[7mA float for pts_time for the splice command is required.\033[27m"
                )
            nbin.add_int(int(self.as_ticks(self.pts_time)), 33)
        else:
            nbin.reserve(7)

fixed.