iheartradio / open-m3u8

Open Source m3u8 Parser
Other
248 stars 94 forks source link

Ignore wrong durations #22

Closed turboezh closed 8 years ago

turboezh commented 8 years ago

I faced the case when a duration in EXTINF tag was given as negative integer (-1), because it was a list of infinite audio streams. (Here the link to the M3U list of the internet radio: http://promodj.com/radio/channels-hq.m3u)

#EXTM3U
#EXTINF:-1,TOP 100
http://radio.promodj.com:8000/top100-192
#EXTINF:-1,Channel 5
http://radio.promodj.com:8000/channel5-192
#EXTINF:-1,Klubb
http://radio.promodj.com:8000/klubb-192

So I've got "com.iheartradio.m3u8.ParseException: bad format found for an EXT tag".

Specification talks about positive integers and floating points only, but real life dictates own rules. Maybe it's better just to ignore wrong duration?

Version 0.1.2

Wopple commented 8 years ago

It is difficult to determine what is the correct decision here. The specification is explicit about the value being non-negative. However, frequently consumers have no control over the production of the playlist files, and those producers keep using their own conventions. Why do they call it an m3u8 playlist when it doesn't follow the specification? It is very frustrating.

I will provide a way to run the parsing in a lenient mode which will parse some non-conformant playlists such as the one above.

Wopple commented 8 years ago

Is that an actual playlist file you need to parse? It is also missing the EXT-X-TARGETDURATION tag which is required. It makes sense they think it's not necessary since all the playlists have infinite duration. There are all sorts of new challenges today! :)

Wopple commented 8 years ago

@turboezh I just released 0.2.0, please give it a couple hours before being made publicly available on maven central.

To address your concerns, ParsingMode now has an option to allow negative numbers. Either use ParsingMode.LENIENT when building the parser, or build your own ParserMode and call ParsingMode.Builder.allowNegativeNumbers().

It will now default EXT-X-TARGETDURATION to the highest value of the media durations with a minimum value of 0 only if the tag is missing.

You may also want to be aware of the full list of changes since there are quite a few: https://github.com/iheartradio/open-m3u8/releases/tag/version-0.2.0

Please let me know if this works for you!

turboezh commented 8 years ago

Now it works. Thank you for fast response. =)