Repository: streamlink/streamlink
Pull request #1707 (2018-05-29 12:19:41)

stream.hls_playlist: removed int check from PROGRAM-ID
```
error: Failed to parse playlist: invalid literal for int() with base 10: 'be38842539da4fe7ad5265ec9ced7153'
```

https://rutube.ru/video/11bbbec75a2ceb8cf446ad16813c6eec/

```
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=be38842539da4fe7ad5265ec9ced7153, BANDWIDTH=700000, CODECS="avc1.42E01E,mp4a.40.5"
288p.m3u8?i=512x288_700000
#EXT-X-STREAM-INF:PROGRAM-ID=be38842539da4fe7ad5265ec9ced7153, BANDWIDTH=700000, CODECS="avc1.42E01E,mp4a.40.5"
288p.m3u8?i=512x288_700000
#EXT-X-STREAM-INF:PROGRAM-ID=be38842539da4fe7ad5265ec9ced7153, BANDWIDTH=1300000, CODECS="avc1.42c01f,mp4a.40.5"
360p.m3u8?i=640x360_1300000
#EXT-X-STREAM-INF:PROGRAM-ID=be38842539da4fe7ad5265ec9ced7153, BANDWIDTH=1300000, CODECS="avc1.42c01f,mp4a.40.5"
360p.m3u8?i=640x360_1300000
#EXT-X-STREAM-INF:PROGRAM-ID=be38842539da4fe7ad5265ec9ced7153, BANDWIDTH=2000000, CODECS="avc1.4D401F,mp4a.40.5"
576p.m3u8?i=896x504_2000000
#EXT-X-STREAM-INF:PROGRAM-ID=be38842539da4fe7ad5265ec9ced7153, BANDWIDTH=2000000, CODECS="avc1.4D401F,mp4a.40.5"
576p.m3u8?i=896x504_2000000
#EXT-X-STREAM-INF:PROGRAM-ID=be38842539da4fe7ad5265ec9ced7153, BANDWIDTH=3600000, CODECS="avc1.640029,mp4a.40.5"
720p.m3u8?i=1280x720_3600000
#EXT-X-STREAM-INF:PROGRAM-ID=be38842539da4fe7ad5265ec9ced7153, BANDWIDTH=3600000, CODECS="avc1.640029,mp4a.40.5"
720p.m3u8?i=1280x720_3600000
```

codecov[bot]: # [Codecov](https://codecov.io/gh/streamlink/streamlink/pull/1707?src=pr&el=h1) Report
> Merging [#1707](https://codecov.io/gh/streamlink/streamlink/pull/1707?src=pr&el=desc) into [master](https://codecov.io/gh/streamlink/streamlink/commit/757861d94eee4543087482e5646a3f5d17cc9404?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `50%`.


```diff
@@            Coverage Diff             @@
##           master    #1707      +/-   ##
==========================================
- Coverage   34.29%   34.29%   -0.01%     
==========================================
  Files         234      234              
  Lines       13102    13105       +3     
==========================================
+ Hits         4493     4494       +1     
- Misses       8609     8611       +2
```

beardypig: I don't think `PROGRAM-ID` is currently used anywhere, so maybe it's better to treat it as a string?
back-to: how do you prefer it

1. completely removed

```diff
--- a/src/streamlink/stream/hls_playlist.py
+++ b/src/streamlink/stream/hls_playlist.py
@@ -67,11 +67,6 @@ class M3U8Parser(object):
 
     def create_stream_info(self, streaminf, cls=None):
         program_id = streaminf.get("PROGRAM-ID")
-        if program_id:
-            try:
-                program_id = int(program_id)
-            except ValueError:
-                program_id = ""
 
         bandwidth = streaminf.get("BANDWIDTH")
         if bandwidth:
```

2. just `str()`
3. `str()` from `from .compat import str`

```diff
--- a/src/streamlink/stream/hls_playlist.py
+++ b/src/streamlink/stream/hls_playlist.py
@@ -68,10 +68,7 @@ class M3U8Parser(object):
     def create_stream_info(self, streaminf, cls=None):
         program_id = streaminf.get("PROGRAM-ID")
         if program_id:
-            try:
-                program_id = int(program_id)
-            except ValueError:
-                program_id = ""
+            program_id = str(program_id)
```
beardypig: I think 1. is fine, leave it untouched - later if we need to we can change it. 
beardypig: Of course, there are some tests that expect it to be an int (`test_hls_playlist.TestHLSPlaylist`).
back-to: yes, I just use `'1'` for now as it's **not used anywhere in the code** as an **int**

but https://github.com/streamlink/streamlink/pull/1646 will be affected
beardypig: I'll fix those once this is merged :) 
gravyboat: Thanks @back-to and @beardypig.

Patch:
diff --git a/src/streamlink/stream/hls_playlist.py b/src/streamlink/stream/hls_playlist.py
index bf916529..7f027218 100644
--- a/src/streamlink/stream/hls_playlist.py
+++ b/src/streamlink/stream/hls_playlist.py
@@ -67,8 +67,6 @@ class M3U8Parser(object):
 
     def create_stream_info(self, streaminf, cls=None):
         program_id = streaminf.get("PROGRAM-ID")
-        if program_id:
-            program_id = int(program_id)
 
         bandwidth = streaminf.get("BANDWIDTH")
         if bandwidth:


Test patch:
diff --git a/tests/test_hls_playlist.py b/tests/test_hls_playlist.py
index 7ba9f3af..6383eb5b 100644
--- a/tests/test_hls_playlist.py
+++ b/tests/test_hls_playlist.py
@@ -69,27 +69,27 @@ class TestHLSPlaylist(unittest.TestCase):
                                 characteristics=None)])
 
         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=258157.0, 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=520929.0, 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=831270.0, 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=1144430.0, 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=1558322.0, 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=4149264.0, 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=6214307.0, 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=10285391.0, program_id='1', codecs=['avc1.4d4033', 'mp4a.40.2'],
                                      resolution=Resolution(width=4096, height=1744), audio='surround', video=None,
                                      subtitles='subs')])