Skip to content

Commit

Permalink
Give the same treatment to EXT-X-CUE-OUT
Browse files Browse the repository at this point in the history
  • Loading branch information
bbayles committed Jul 30, 2024
1 parent 1763161 commit 3c0443e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 44 deletions.
59 changes: 16 additions & 43 deletions m3u8/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,55 +583,28 @@ def _parse_cueout_cont(line, state, **kwargs):
state["current_cue_out_elapsedtime"] = elapsedtime


def _cueout_no_duration(line):
# this needs to be called first since line.split in all other
# parsers will throw a ValueError if passed just this tag
if line == protocol.ext_x_cue_out:
return (None, None)


def _cueout_envivio(line, state):
param, value = line.split(":", 1)
res = re.match('.*DURATION=(.*),.*,CUE="(.*)"', value)
if res:
return (res.group(2), res.group(1))
else:
return None


def _cueout_duration(line):
# This was added separately rather than modifying "simple"
param, value = line.split(":", 1)
res = re.match(r"DURATION=(.*)", value)
if res:
return (None, res.group(1))


def _cueout_simple(line):
param, value = line.split(":", 1)
res = re.match(r"^(\d+(?:\.\d)?\d*)$", value)
if res:
return (None, res.group(1))


def _parse_cueout(line, state, **kwargs):
_cueout_state = (
_cueout_no_duration(line)
or _cueout_envivio(line, state)
or _cueout_duration(line)
or _cueout_simple(line)
)
if _cueout_state:
cue_out_scte35, cue_out_duration = _cueout_state
current_cue_out_scte35 = state.get("current_cue_out_scte35")
state["current_cue_out_scte35"] = cue_out_scte35 or current_cue_out_scte35
state["current_cue_out_duration"] = cue_out_duration

state["cue_out_start"] = True
state["cue_out"] = True
if "DURATION" in line.upper():
state["cue_out_explicitly_duration"] = True

elements = line.split(":", 1)
if len(elements) != 2:
return

cue_info = _parse_attribute_list(
protocol.ext_x_cue_out,
line,
remove_quotes_parser("cue"),
)
cue_out_scte35 = cue_info.get("cue")
cue_out_duration = cue_info.get("duration") or cue_info.get("")

current_cue_out_scte35 = state.get("current_cue_out_scte35")
state["current_cue_out_scte35"] = cue_out_scte35 or current_cue_out_scte35
state["current_cue_out_duration"] = cue_out_duration


def _parse_server_control(line, data, **kwargs):
attribute_parser = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_segment_envivio_scte35_attribute():
def test_segment_unknown_scte35_attribute():
obj = m3u8.M3U8(playlists.CUE_OUT_INVALID_PLAYLIST)
assert obj.segments[0].scte35 is None
assert obj.segments[0].scte35_duration is None
assert obj.segments[0].scte35_duration == "INVALID"


def test_segment_cue_out_no_duration():
Expand Down

0 comments on commit 3c0443e

Please sign in to comment.