Skip to content

Commit

Permalink
Merge pull request #125 from cdunklau/dequote-closed-captions
Browse files Browse the repository at this point in the history
Dequote CLOSED-CAPTIONS AttributeValue in STREAM-INF
  • Loading branch information
leandromoreira authored Oct 11, 2018
2 parents 6a97b29 + c20ff50 commit 12550e3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion m3u8/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,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')
atribute_parser = remove_quotes_parser('codecs', 'audio', 'video', 'subtitles', 'closed_captions')
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 @@ -88,6 +88,14 @@
http://example.com/audio-only.m3u8
'''

VARIANT_PLAYLIST_WITH_CC_SUBS_AND_AUDIO = '''
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=7680000,CLOSED-CAPTIONS="cc",SUBTITLES="sub",AUDIO="aud"
http://example.com/with-cc-hi.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=65000,CLOSED-CAPTIONS="cc",SUBTITLES="sub",AUDIO="aud"
http://example.com/with-cc-low.m3u8
'''

VARIANT_PLAYLIST_WITH_AVERAGE_BANDWIDTH = '''
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1280000,AVERAGE-BANDWIDTH=1252345
Expand Down
22 changes: 22 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ def test_should_parse_variant_playlist():
assert 65000 == playlists_list[-1]['stream_info']['bandwidth']
assert 'mp4a.40.5,avc1.42801e' == playlists_list[-1]['stream_info']['codecs']

def test_should_parse_variant_playlist_with_cc_subtitles_and_audio():
data = m3u8.parse(playlists.VARIANT_PLAYLIST_WITH_CC_SUBS_AND_AUDIO)
playlists_list = list(data['playlists'])

assert True == data['is_variant']
assert None == data['media_sequence']
assert 2 == len(playlists_list)

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 '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 'sub' == playlists_list[-1]['stream_info']['subtitles']
assert 'aud' == playlists_list[-1]['stream_info']['audio']

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 12550e3

Please sign in to comment.