Skip to content

Commit 1b4000d

Browse files
committed
Always parse target duration as integer
Following the HLS spec, target duration is an integer value.
1 parent 1f62ed2 commit 1b4000d

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

m3u8/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def _parse_byterange(line, state, **kwargs):
452452

453453

454454
def _parse_targetduration(**parse_kwargs):
455-
return _parse_simple_parameter(cast_to=float, **parse_kwargs)
455+
return _parse_simple_parameter(cast_to=int, **parse_kwargs)
456456

457457

458458
def _parse_media_sequence(**parse_kwargs):

tests/playlists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
PLAYLIST_WITH_NON_INTEGER_DURATION = """
6767
#EXTM3U
68-
#EXT-X-TARGETDURATION:5220.5
68+
#EXT-X-TARGETDURATION:5221
6969
#EXTINF:5220.5,
7070
http://media.example.com/entire.ts
7171
"""

tests/test_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_should_parse_simple_playlist_from_string():
2828

2929
def test_should_parse_non_integer_duration_from_playlist_string():
3030
data = m3u8.parse(playlists.PLAYLIST_WITH_NON_INTEGER_DURATION)
31-
assert 5220.5 == data["targetduration"]
31+
assert 5221 == data["targetduration"]
3232
assert [5220.5] == [c["duration"] for c in data["segments"]]
3333

3434

0 commit comments

Comments
 (0)