diff --git a/m3u8/parser.py b/m3u8/parser.py index 3f17d8a4..28b2e155 100644 --- a/m3u8/parser.py +++ b/m3u8/parser.py @@ -319,6 +319,9 @@ def _parse_attribute_list(prefix, line, attribute_parser, default_parser=None): params = ATTRIBUTELISTPATTERN.split(line.replace(prefix + ":", ""))[1::2] attributes = {} + if not line.startswith(prefix+':') : + return attributes + for param in params: param_parts = param.split("=", 1) if len(param_parts) == 1: diff --git a/tests/playlists.py b/tests/playlists.py index 2e3063d0..14338a31 100755 --- a/tests/playlists.py +++ b/tests/playlists.py @@ -98,7 +98,19 @@ http://media.example.com/fileSequence52-3.ts """ -PLAYLIST_WITH_SESSION_ENCRYPTED_SEGMENTS = """ +PLAYLIST_WITH_CUSTOM_MEDIA_HEADER = '''#EXTM3U +#EXT-X-VERSION:3 +#EXT-X-TARGETDURATION:6 +#EXT-X-MEDIA-SEQUENCE:1 +#EXT-X-MEDIA-READY:7f659f6f09bce196d7 +#EXT-X-KEY:METHOD=AES-128,URI="[KEY]",IV=[IV] +#EXTINF:6.0, +https://cdn.example.com/vod/hash:XXX/file.mp4/media-1.ts +#EXTINF:6.28, +https://cdn.example.com/vod/hash:XXX/file.mp4/media-2.ts +''' + +PLAYLIST_WITH_SESSION_ENCRYPTED_SEGMENTS = ''' #EXTM3U #EXT-X-MEDIA-SEQUENCE:7794 #EXT-X-TARGETDURATION:15 @@ -111,7 +123,7 @@ http://media.example.com/fileSequence52-2.ts #EXTINF:15, http://media.example.com/fileSequence52-3.ts -""" +''' VARIANT_PLAYLIST = """ #EXTM3U diff --git a/tests/test_model.py b/tests/test_model.py index 0789ad15..e87afab2 100755 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -382,6 +382,10 @@ def test_session_key_attribute_without_initialization_vector(): assert None is obj.session_keys[0].iv +def test_parse_custom_media_header(): + obj = m3u8.M3U8(playlists.PLAYLIST_WITH_CUSTOM_MEDIA_HEADER) + + def test_segments_attribute(): obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST) mock_parser_data(