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():