Skip to content

Commit

Permalink
Interpret raw values as they are
Browse files Browse the repository at this point in the history
Before this commit, a negative number was resulting
in a bad value. -10 was being replaced with _10, raising
undesired exceptions.
  • Loading branch information
mauricioabreu committed Jan 19, 2020
1 parent 0cc3ac3 commit 06840c6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion m3u8/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,6 @@ def find_key(keydata, keylist):
def denormalize_attribute(attribute):
return attribute.replace('_', '-').upper()


def quoted(string):
return '"%s"' % string

Expand Down
2 changes: 1 addition & 1 deletion m3u8/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def _parse_simple_parameter_raw_value(line, cast_to=str, normalize=False):
param, value = line.split(':', 1)
param = normalize_attribute(param.replace('#EXT-X-', ''))
if normalize:
value = normalize_attribute(value)
value = value.strip().lower()
return param, cast_to(value)


Expand Down
9 changes: 9 additions & 0 deletions tests/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,4 +919,13 @@
#EXT-X-VERSION:4
'''

PLAYLIST_WITH_NEGATIVE_MEDIA_SEQUENCE = '''
#EXTM3U
#EXT-X-TARGETDURATION:5220
#EXT-X-MEDIA-SEQUENCE:-2680
#EXTINF:5220,
http://media.example.com/entire.ts
#EXT-X-ENDLIST
'''

del abspath, dirname, join
5 changes: 5 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,8 @@ def test_low_latency_playlist():
assert data['rendition_reports'][0]['uri'] == "../1M/waitForMSN.php"
assert data['rendition_reports'][0]['last_msn'] == 273
assert data['rendition_reports'][0]['last_part'] == 3


def test_negative_media_sequence():
data = m3u8.parse(playlists.PLAYLIST_WITH_NEGATIVE_MEDIA_SEQUENCE)
assert data['media_sequence'] == -2680

0 comments on commit 06840c6

Please sign in to comment.