Skip to content

Commit

Permalink
Merge pull request #48 from mvmocanu/master
Browse files Browse the repository at this point in the history
Add support for #EXT-X-INDEPENDENT-SEGMENTS fix #51 and fix #52
  • Loading branch information
leandromoreira committed Jul 24, 2015
2 parents 74aa57e + 3811ec4 commit 8b31976
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions m3u8/model.py
Expand Up @@ -105,6 +105,10 @@ class M3U8(object):
Returns true if EXT-X-I-FRAMES-ONLY tag present in M3U8.
http://tools.ietf.org/html/draft-pantos-http-live-streaming-07#section-3.3.12
`is_independent_segments`
Returns true if EXT-X-INDEPENDENT-SEGMENTS tag present in M3U8.
https://tools.ietf.org/html/draft-pantos-http-live-streaming-13#section-3.4.16
'''

simple_attributes = (
Expand All @@ -115,6 +119,7 @@ class M3U8(object):
('target_duration', 'targetduration'),
('media_sequence', 'media_sequence'),
('program_date_time', 'program_date_time'),
('is_independent_segments', 'is_independent_segments'),
('version', 'version'),
('allow_cache', 'allow_cache'),
('playlist_type', 'playlist_type')
Expand Down Expand Up @@ -212,6 +217,8 @@ def dumps(self):
You could also use unicode(<this obj>) or str(<this obj>)
'''
output = ['#EXTM3U']
if self.is_independent_segments:
output.append('#EXT-X-INDEPENDENT-SEGMENTS')
if self.media_sequence > 0:
output.append('#EXT-X-MEDIA-SEQUENCE:' + str(self.media_sequence))
if self.allow_cache:
Expand Down
4 changes: 4 additions & 0 deletions m3u8/parser.py
Expand Up @@ -39,6 +39,7 @@ def parse(content, strict=False):
'is_variant': False,
'is_endlist': False,
'is_i_frames_only': False,
'is_independent_segments': False,
'playlist_type': None,
'playlists': [],
'iframe_playlists': [],
Expand Down Expand Up @@ -108,6 +109,9 @@ def parse(content, strict=False):
elif line.startswith(protocol.ext_i_frames_only):
data['is_i_frames_only'] = True

elif line.startswith(protocol.ext_is_independent_segments):
data['is_independent_segments'] = True

elif line.startswith(protocol.ext_x_endlist):
data['is_endlist'] = True

Expand Down
3 changes: 2 additions & 1 deletion m3u8/protocol.py
Expand Up @@ -18,4 +18,5 @@
ext_x_byterange = '#EXT-X-BYTERANGE'
ext_x_i_frame_stream_inf = '#EXT-X-I-FRAME-STREAM-INF'
ext_x_discontinuity = '#EXT-X-DISCONTINUITY'
ext_x_cue_out = '#EXT-X-CUE-OUT-CONT'
ext_x_cue_out = '#EXT-X-CUE-OUT-CONT'
ext_is_independent_segments = '#EXT-X-INDEPENDENT-SEGMENTS'
1 change: 1 addition & 0 deletions requirements-dev.txt
@@ -1,4 +1,5 @@
-r requirements.txt
arrow
pytest
bottle
pytest-cov
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -11,7 +11,7 @@
name="m3u8",
author='Globo.com',
author_email='videos3@corp.globo.com',
version="0.2.5",
version="0.2.6",
zip_safe=False,
include_package_data=True,
install_requires=install_reqs,
Expand Down
8 changes: 8 additions & 0 deletions tests/playlists.py
Expand Up @@ -225,6 +225,14 @@
#EXT-X-ENDLIST
'''

SIMPLE_PLAYLIST_WITH_INDEPENDENT_SEGMENTS = '''
#EXTM3U
#EXT-X-INDEPENDENT-SEGMENTS
#EXTINF:180.00000,
some_video.ts
#EXT-X-ENDLIST
'''

SIMPLE_PLAYLIST_WITH_EVENT_PLAYLIST_TYPE = '''
#EXTM3U
#EXT-X-PLAYLIST-TYPE:EVENT
Expand Down
8 changes: 8 additions & 0 deletions tests/test_model.py
Expand Up @@ -313,6 +313,14 @@ def test_event_playlist_type_should_be_imported_as_a_simple_attribute():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST_WITH_EVENT_PLAYLIST_TYPE)
assert obj.playlist_type == 'event'

def test_independent_segments_should_be_true():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST_WITH_INDEPENDENT_SEGMENTS)
assert obj.is_independent_segments

def test_independent_segments_should_be_false():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST_WITH_EVENT_PLAYLIST_TYPE)
assert not obj.is_independent_segments

def test_no_playlist_type_leaves_attribute_empty():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST)
assert obj.playlist_type is None
Expand Down

0 comments on commit 8b31976

Please sign in to comment.