Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subtitles, video, and audio group-id refs to StreamInfo #126

Merged
merged 2 commits into from
Oct 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
'''

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use fake uri (i.e: http://example.com/cc.srt) instead of `"cc".

CLOSED-CAPTION does not specify a Rendition; the closed caption
      media is present in the Media Segments of every video Rendition.

      URI

      The value is a quoted-string containing a URI that identifies the
      Media Playlist file.  This attribute is OPTIONAL; see
      Section 4.3.4.2.1.  If the TYPE is CLOSED-CAPTIONS, the URI
      attribute MUST NOT be present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're conflating the URI attribute of EXT-X-I-FRAME-STREAM-INF with the URI line that must follow EXT-X-STREAM-INF. In EXT-X-STREAM-INF, the CLOSED-CAPTIONS, AUDIO, VIDEO, and SUBTITLES attributes all reference a "GROUP-ID attribute of an EXT-X-MEDIA tag elsewhere".

However, reviewing this made me realize that StreamInfo for EXT-X-I-FRAME-STREAM-INF should have audio, subtitles, and closed-captions set to None explicitly.

All attributes defined for the EXT-X-STREAM-INF tag (Section 4.3.4.2)
are also defined for the EXT-X-I-FRAME-STREAM-INF tag, except for the
FRAME-RATE, AUDIO, SUBTITLES, and CLOSED-CAPTIONS attributes.

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