Repository: streamlink/streamlink
Pull request #3721 (2021-05-08 11:20:02)

stream.hls_playlist: round BANDWIDTH and parse as int
same as DASH Streams https://github.com/streamlink/streamlink/pull/1995

---

before

```
[cli][info] Available streams: 360p_364k (worst), 480p_764k, 720p_1564k, 720p_2564k, 576p_5008k, 720p_6891k, 720p_9726k (best)
```

now

```
[cli][info] Available streams: 360p_360k (worst), 480p_760k, 720p_1600k, 720p_2600k, 576p_5000k, 720p_6900k, 720p_9700k (best)
```

---

useful for https://github.com/streamlink/streamlink/issues/3708


Patch:
diff --git a/src/streamlink/plugins/mitele.py b/src/streamlink/plugins/mitele.py
index 50c6ec74..67767d42 100644
--- a/src/streamlink/plugins/mitele.py
+++ b/src/streamlink/plugins/mitele.py
@@ -78,6 +78,7 @@ class Mitele(Plugin):
                                                                     self.token_errors.get(tokens["code"], "unknown error")))
             return
 
+        list_urls = []
         for stream in pdata["dls"]:
             if stream["drm"]:
                 log.warning("Stream may be protected by DRM")
@@ -87,7 +88,13 @@ class Mitele(Plugin):
                 cdn_token = tokens.get(stream["lid"], {}).get("cdn", "")
                 qsd = parse_qsd(cdn_token)
                 if sformat == "hls":
-                    yield from HLSStream.parse_variant_playlist(self.session, update_qsd(stream["stream"], qsd)).items()
+                    list_urls.append(update_qsd(stream["stream"], qsd))
+
+        if not list_urls:
+            return
+
+        for url in list(set(list_urls)):
+            yield from HLSStream.parse_variant_playlist(self.session, url, name_fmt="{pixels}_{bitrate}").items()
 
 
 __plugin__ = Mitele
diff --git a/src/streamlink/stream/hls_playlist.py b/src/streamlink/stream/hls_playlist.py
index d0ab6fc3..d36ddb74 100644
--- a/src/streamlink/stream/hls_playlist.py
+++ b/src/streamlink/stream/hls_playlist.py
@@ -1,4 +1,5 @@
 import logging
+import math
 import re
 from binascii import unhexlify
 from collections import namedtuple
@@ -94,7 +95,7 @@ class M3U8Parser:
 
         bandwidth = streaminf.get("BANDWIDTH")
         if bandwidth:
-            bandwidth = float(bandwidth)
+            bandwidth = round(int(bandwidth), 1 - int(math.log10(int(bandwidth))))
 
         resolution = streaminf.get("RESOLUTION")
         if resolution:


Test patch:
diff --git a/tests/streams/test_hls_playlist.py b/tests/streams/test_hls_playlist.py
index 811b3adc..a18606cd 100644
--- a/tests/streams/test_hls_playlist.py
+++ b/tests/streams/test_hls_playlist.py
@@ -41,28 +41,28 @@ class TestHLSPlaylist(unittest.TestCase):
         self.assertEqual(
             [p.stream_info for p in playlist.playlists],
             [
-                StreamInfo(bandwidth=258157.0, program_id='1', codecs=['avc1.4d400d', 'mp4a.40.2'],
+                StreamInfo(bandwidth=260000, program_id='1', codecs=['avc1.4d400d', 'mp4a.40.2'],
                            resolution=Resolution(width=422, height=180), audio='stereo', video=None,
                            subtitles='subs'),
-                StreamInfo(bandwidth=520929.0, program_id='1', codecs=['avc1.4d4015', 'mp4a.40.2'],
+                StreamInfo(bandwidth=520000, program_id='1', codecs=['avc1.4d4015', 'mp4a.40.2'],
                            resolution=Resolution(width=638, height=272), audio='stereo', video=None,
                            subtitles='subs'),
-                StreamInfo(bandwidth=831270.0, program_id='1', codecs=['avc1.4d4015', 'mp4a.40.2'],
+                StreamInfo(bandwidth=830000, program_id='1', codecs=['avc1.4d4015', 'mp4a.40.2'],
                            resolution=Resolution(width=638, height=272), audio='stereo', video=None,
                            subtitles='subs'),
-                StreamInfo(bandwidth=1144430.0, program_id='1', codecs=['avc1.4d401f', 'mp4a.40.2'],
+                StreamInfo(bandwidth=1100000, program_id='1', codecs=['avc1.4d401f', 'mp4a.40.2'],
                            resolution=Resolution(width=958, height=408), audio='surround', video=None,
                            subtitles='subs'),
-                StreamInfo(bandwidth=1558322.0, program_id='1', codecs=['avc1.4d401f', 'mp4a.40.2'],
+                StreamInfo(bandwidth=1600000, program_id='1', codecs=['avc1.4d401f', 'mp4a.40.2'],
                            resolution=Resolution(width=1277, height=554), audio='surround', video=None,
                            subtitles='subs'),
-                StreamInfo(bandwidth=4149264.0, program_id='1', codecs=['avc1.4d4028', 'mp4a.40.2'],
+                StreamInfo(bandwidth=4100000, program_id='1', codecs=['avc1.4d4028', 'mp4a.40.2'],
                            resolution=Resolution(width=1921, height=818), audio='surround', video=None,
                            subtitles='subs'),
-                StreamInfo(bandwidth=6214307.0, program_id='1', codecs=['avc1.4d4028', 'mp4a.40.2'],
+                StreamInfo(bandwidth=6200000, program_id='1', codecs=['avc1.4d4028', 'mp4a.40.2'],
                            resolution=Resolution(width=1921, height=818), audio='surround', video=None,
                            subtitles='subs'),
-                StreamInfo(bandwidth=10285391.0, program_id='1', codecs=['avc1.4d4033', 'mp4a.40.2'],
+                StreamInfo(bandwidth=10000000, program_id='1', codecs=['avc1.4d4033', 'mp4a.40.2'],
                            resolution=Resolution(width=4096, height=1744), audio='surround', video=None,
                            subtitles='subs')
             ]