From ce920a9f60ea0b7f3b40c2d40cce36959f20bbbe Mon Sep 17 00:00:00 2001 From: Colin Dunklau Date: Fri, 12 Oct 2018 14:25:22 +0200 Subject: [PATCH 1/2] Add subtitles, video, and audio group-id refs to StreamInfo --- m3u8/model.py | 8 +++++++- tests/playlists.py | 8 ++++++++ tests/test_model.py | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/m3u8/model.py b/m3u8/model.py index 3f9aa28d..b29c0034 100644 --- a/m3u8/model.py +++ b/m3u8/model.py @@ -490,6 +490,9 @@ def __init__(self, uri, stream_info, media, base_uri): self.stream_info = StreamInfo( bandwidth=stream_info['bandwidth'], + video=stream_info.get('video'), + audio=stream_info.get('audio'), + subtitles=stream_info.get('subtitles'), closed_captions=stream_info.get('closed_captions'), average_bandwidth=stream_info.get('average_bandwidth'), program_id=stream_info.get('program_id'), @@ -561,6 +564,9 @@ def __init__(self, base_uri, uri, iframe_stream_info): self.iframe_stream_info = StreamInfo( bandwidth=iframe_stream_info.get('bandwidth'), + video=iframe_stream_info.get('video'), + audio=iframe_stream_info.get('audio'), + subtitles=iframe_stream_info.get('subtitles'), closed_captions=iframe_stream_info.get('closed_captions'), average_bandwidth=None, program_id=iframe_stream_info.get('program_id'), @@ -590,7 +596,7 @@ def __str__(self): StreamInfo = namedtuple( 'StreamInfo', - ['bandwidth', 'closed_captions', 'average_bandwidth', 'program_id', 'resolution', 'codecs'] + ['bandwidth', 'closed_captions', 'average_bandwidth', 'program_id', 'resolution', 'codecs', 'audio', 'video', 'subtitles'] ) diff --git a/tests/playlists.py b/tests/playlists.py index fbec958c..dc3ef6cc 100755 --- a/tests/playlists.py +++ b/tests/playlists.py @@ -96,6 +96,14 @@ http://example.com/with-cc-low.m3u8 ''' +VARIANT_PLAYLIST_WITH_VIDEO_CC_SUBS_AND_AUDIO = ''' +#EXTM3U +#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=7680000,CLOSED-CAPTIONS="cc",SUBTITLES="sub",AUDIO="aud",VIDEO="vid" +http://example.com/with-everything-hi.m3u8 +#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=65000,CLOSED-CAPTIONS="cc",SUBTITLES="sub",AUDIO="aud",VIDEO="vid" +http://example.com/with-everything-low.m3u8 +''' + VARIANT_PLAYLIST_WITH_AVERAGE_BANDWIDTH = ''' #EXTM3U #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1280000,AVERAGE-BANDWIDTH=1252345 diff --git a/tests/test_model.py b/tests/test_model.py index 8e53a754..105946a9 100755 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -743,6 +743,16 @@ def test_start_with_precise(): assert ext_x_start + ':TIME-OFFSET=10.5,PRECISE=YES\n' in obj.dumps() +def test_playlist_stream_info_contains_group_id_refs(): + obj = m3u8.M3U8(playlists.VARIANT_PLAYLIST_WITH_VIDEO_CC_SUBS_AND_AUDIO) + assert len(obj.playlists) == 2 + for pl in obj.playlists: + assert pl.stream_info.closed_captions == 'cc' + assert pl.stream_info.subtitles == 'sub' + assert pl.stream_info.audio == 'aud' + assert pl.stream_info.video == 'vid' + + # custom asserts From fb6ef2aed4df5cb2406c9b322eedd5b126cb0de1 Mon Sep 17 00:00:00 2001 From: Colin Dunklau Date: Fri, 12 Oct 2018 20:53:18 +0200 Subject: [PATCH 2/2] Hardcode some StreamInfo attributes in IFramePlaylist --- m3u8/model.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/m3u8/model.py b/m3u8/model.py index b29c0034..da00b57f 100644 --- a/m3u8/model.py +++ b/m3u8/model.py @@ -565,9 +565,11 @@ def __init__(self, base_uri, uri, iframe_stream_info): self.iframe_stream_info = StreamInfo( bandwidth=iframe_stream_info.get('bandwidth'), video=iframe_stream_info.get('video'), - audio=iframe_stream_info.get('audio'), - subtitles=iframe_stream_info.get('subtitles'), - closed_captions=iframe_stream_info.get('closed_captions'), + # Audio, subtitles, and closed captions should not exist in + # EXT-X-I-FRAME-STREAM-INF, so just hardcode them to None. + audio=None, + subtitles=None, + closed_captions=None, average_bandwidth=None, program_id=iframe_stream_info.get('program_id'), resolution=resolution_pair,