Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_commaless_extinf_strict():
with pytest.raises(ParseError) as e:
m3u8.parse(playlists.SIMPLE_PLAYLIST_COMMALESS_EXTINF, strict=True)
assert str(e.value) == 'Syntax error in manifest on line 3: #EXTINF:5220'
def test_parse_simple_playlist_messy_strict():
with pytest.raises(ParseError) as catch:
m3u8.parse(playlists.SIMPLE_PLAYLIST_MESSY, strict=True)
assert str(catch.value) == 'Syntax error in manifest on line 5: JUNK'
def _parse_extinf(line, data, state, lineno, strict):
chunks = line.replace(protocol.extinf + ':', '').split(',', 1)
if len(chunks) == 2:
duration, title = chunks
elif len(chunks) == 1:
if strict:
raise ParseError(lineno, line)
else:
duration = chunks[0]
title = ''
if 'segment' not in state:
state['segment'] = {}
state['segment']['duration'] = float(duration)
state['segment']['title'] = title
custom_tags_parser(line, data, lineno)
elif line.strip() == '':
# blank lines are legal
pass
elif state['expect_segment']:
_parse_ts_chunk(line, data, state)
state['expect_segment'] = False
elif state['expect_playlist']:
_parse_variant_playlist(line, data, state)
state['expect_playlist'] = False
elif strict:
raise ParseError(lineno, line)
# there could be remaining partial segments
if 'segment' in state:
data['segments'].append(state.pop('segment'))
return data