Skip to content

Commit

Permalink
Follow RFC 8261 section 4.3.4.2 for CLOSED-CAPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
bbayles authored Jul 25, 2022
1 parent 3f5fa1b commit dff1d92
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion m3u8/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _parse_attribute_list(prefix, line, atribute_parser):
def _parse_stream_inf(line, data, state):
data['is_variant'] = True
data['media_sequence'] = None
atribute_parser = remove_quotes_parser('codecs', 'audio', 'video', 'subtitles', 'closed_captions', 'pathway_id', 'stable_variant_id')
atribute_parser = remove_quotes_parser('codecs', 'audio', 'video', 'subtitles', 'pathway_id', 'stable_variant_id')
atribute_parser["program_id"] = int
atribute_parser["bandwidth"] = lambda x: int(float(x))
atribute_parser["average_bandwidth"] = int
Expand Down
8 changes: 8 additions & 0 deletions tests/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@
http://example.com/with-cc-low.m3u8
'''

VARIANT_PLAYLIST_WITH_NONE_CC_AND_AUDIO = '''
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=7680000,CLOSED-CAPTIONS=NONE,SUBTITLES="sub",AUDIO="aud"
http://example.com/with-cc-hi.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=65000,CLOSED-CAPTIONS=NONE,SUBTITLES="sub",AUDIO="aud"
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"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ 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.closed_captions == '"cc"'
assert pl.stream_info.subtitles == 'sub'
assert pl.stream_info.audio == 'aud'
assert pl.stream_info.video == 'vid'
Expand Down
11 changes: 9 additions & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,24 @@ def test_should_parse_variant_playlist_with_cc_subtitles_and_audio():
assert 'http://example.com/with-cc-hi.m3u8' == playlists_list[0]['uri']
assert 1 == playlists_list[0]['stream_info']['program_id']
assert 7680000 == playlists_list[0]['stream_info']['bandwidth']
assert 'cc' == playlists_list[0]['stream_info']['closed_captions']
assert '"cc"' == playlists_list[0]['stream_info']['closed_captions']
assert 'sub' == playlists_list[0]['stream_info']['subtitles']
assert 'aud' == playlists_list[0]['stream_info']['audio']

assert 'http://example.com/with-cc-low.m3u8' == playlists_list[-1]['uri']
assert 1 == playlists_list[-1]['stream_info']['program_id']
assert 65000 == playlists_list[-1]['stream_info']['bandwidth']
assert 'cc' == playlists_list[-1]['stream_info']['closed_captions']
assert '"cc"' == playlists_list[-1]['stream_info']['closed_captions']
assert 'sub' == playlists_list[-1]['stream_info']['subtitles']
assert 'aud' == playlists_list[-1]['stream_info']['audio']

def test_should_parse_variant_playlist_with_none_cc_and_audio():
data = m3u8.parse(playlists.VARIANT_PLAYLIST_WITH_NONE_CC_AND_AUDIO)
playlists_list = list(data['playlists'])

assert 'NONE' == playlists_list[0]['stream_info']['closed_captions']
assert 'NONE' == playlists_list[-1]['stream_info']['closed_captions']

def test_should_parse_variant_playlist_with_average_bandwidth():
data = m3u8.parse(playlists.VARIANT_PLAYLIST_WITH_AVERAGE_BANDWIDTH)
playlists_list = list(data['playlists'])
Expand Down

0 comments on commit dff1d92

Please sign in to comment.