globocom / m3u8

Python m3u8 Parser for HTTP Live Streaming (HLS) Transmissions
Other
2.03k stars 471 forks source link

Empty duration default/exception #344

Closed radujica closed 2 months ago

radujica commented 10 months ago

As raised in https://github.com/radujica/tospotify/issues/27, looks like some music players can store playlists with missing duration in #EXTINF, e.g.

#EXTINF:,Song

which leads to an exception such as

File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/init.py", line 49, in load
return _load_from_file(uri, custom_tags_parser)
File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/init.py", line 56, in _load_from_file
return M3U8(raw_content, base_uri=base_uri, custom_tags_parser=custom_tags_parser)
File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/model.py", line 153, in init
self.data = parse(content, strict, custom_tags_parser)
File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/parser.py", line 143, in parse
_parse_extinf(line, data, state, lineno, strict)
File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/parser.py", line 261, in _parse_extinf
state['segment']['duration'] = float(duration)
ValueError: could not convert string to float: ''

Now according to https://en.wikipedia.org/wiki/M3U, that's technically invalid m3u format, however could perhaps show a better error OR ignore and default to duration=0?

Something like this for option 2: https://github.com/globocom/m3u8/pull/343

mauricioabreu commented 2 months ago

Hello, @radujica sorry for the late reply.

I think the best option here is adding a better message. Since this library is a parser, we should not be adding default values. I hope you understand it.