Skip to content

Commit

Permalink
Merge pull request #126 from cdunklau/expand-streaminfo
Browse files Browse the repository at this point in the history
Add subtitles, video, and audio group-id refs to StreamInfo
  • Loading branch information
leandromoreira authored Oct 13, 2018
2 parents 12550e3 + fb6ef2a commit e499d3c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
12 changes: 10 additions & 2 deletions m3u8/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -561,7 +564,12 @@ def __init__(self, base_uri, uri, iframe_stream_info):

self.iframe_stream_info = StreamInfo(
bandwidth=iframe_stream_info.get('bandwidth'),
closed_captions=iframe_stream_info.get('closed_captions'),
video=iframe_stream_info.get('video'),
# 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,
Expand Down Expand Up @@ -590,7 +598,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']
)


Expand Down
8 changes: 8 additions & 0 deletions tests/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit e499d3c

Please sign in to comment.