Skip to content

Commit

Permalink
Support EXT-X-CUE-OUT:Elapsed/Duration format
Browse files Browse the repository at this point in the history
  • Loading branch information
bbayles authored and mauricioabreu committed Apr 1, 2024
1 parent 306da4c commit 3201055
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions m3u8/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,17 @@ def _parse_cueout_cont(line, state):
if len(elements) != 2:
return

# EXT-X-CUE-OUT-CONT:2.436/120 style
res = re.match(
r"^[-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+)/[-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+)$",
elements[1]
)
if res:
state["current_cue_out_elapsedtime"] = res.group(1)
state["current_cue_out_duration"] = res.group(3)
return

# EXT-X-CUE-OUT-CONT:ElapsedTime=10,Duration=60,SCTE35=... style
cue_info = _parse_attribute_list(
protocol.ext_x_cue_out_cont,
line,
Expand Down
20 changes: 20 additions & 0 deletions tests/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,26 @@
master2500_47234.ts
"""

CUE_OUT_CONT_ALT_PLAYLIST = """
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:19980226
#EXT-X-DISCONTINUITY-SEQUENCE:1
#EXT-X-CUE-OUT:119.987
#EXTINF:2.000,
segment_19980226.ts
#EXT-X-CUE-OUT-CONT:2/120
#EXTINF:6.000,
segment_19980227.ts
#EXT-X-CUE-OUT-CONT:8/120.0
#EXTINF:6.001,
segment_19980228.ts
#EXT-X-CUE-OUT-CONT:14.001/120.0
#EXTINF:6.001,
segment_19980229.ts
"""

CUE_OUT_ENVIVIO_PLAYLIST = """
#EXTM3U
#EXT-X-VERSION:3
Expand Down
14 changes: 14 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ def test_segment_elemental_scte35_attribute():
)


def test_segment_cue_out_cont_alt():
obj = m3u8.M3U8(playlists.CUE_OUT_CONT_ALT_PLAYLIST)
segments = obj.segments

assert segments[1].scte35_elapsedtime == '2'
assert segments[1].scte35_duration == '120'

assert segments[2].scte35_elapsedtime == '8'
assert segments[2].scte35_duration == '120.0'

assert segments[3].scte35_elapsedtime == '14.001'
assert segments[3].scte35_duration == '120.0'


def test_segment_envivio_scte35_attribute():
obj = m3u8.M3U8(playlists.CUE_OUT_ENVIVIO_PLAYLIST)
segments = obj.segments
Expand Down

0 comments on commit 3201055

Please sign in to comment.