From f9cbdfb0ab930b4d7cfdaaa920a79ff2f4e91b82 Mon Sep 17 00:00:00 2001 From: David Evans Date: Wed, 31 Jul 2024 09:47:51 +0100 Subject: [PATCH] Parse Bitrate value as integer not string --- m3u8/model.py | 2 +- m3u8/parser.py | 6 ++++-- tests/test_parser.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/m3u8/model.py b/m3u8/model.py index 716852cc..7f293d1f 100644 --- a/m3u8/model.py +++ b/m3u8/model.py @@ -671,7 +671,7 @@ def dumps(self, last_segment, timespec="milliseconds", infspec="auto"): output.append("#EXT-X-BYTERANGE:%s\n" % self.byterange) if self.bitrate: - output.append("#EXT-X-BITRATE:%s\n" % self.bitrate) + output.append("#EXT-X-BITRATE:%d\n" % self.bitrate) if self.gap_tag: output.append("#EXT-X-GAP\n") diff --git a/m3u8/parser.py b/m3u8/parser.py index c3a9e317..aa3e7f0a 100644 --- a/m3u8/parser.py +++ b/m3u8/parser.py @@ -439,10 +439,12 @@ def _parse_variant_playlist(line, data, state, **kwargs): state["expect_playlist"] = False -def _parse_bitrate(line, state, **kwargs): +def _parse_bitrate(state, **kwargs): if "segment" not in state: state["segment"] = {} - state["segment"]["bitrate"] = line.replace(protocol.ext_x_bitrate + ":", "") + state["segment"]["bitrate"] = _parse_simple_parameter( + cast_to=int, **kwargs + ) def _parse_byterange(line, state, **kwargs): diff --git a/tests/test_parser.py b/tests/test_parser.py index a5015711..dae6f64b 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -856,8 +856,8 @@ def test_delta_playlist_daterange_skipping(): def test_bitrate(): data = m3u8.parse(playlists.BITRATE_PLAYLIST) - assert data["segments"][0]["bitrate"] == "1674" - assert data["segments"][1]["bitrate"] == "1625" + assert data["segments"][0]["bitrate"] == 1674 + assert data["segments"][1]["bitrate"] == 1625 def test_content_steering():