iheartradio / open-m3u8

Open Source m3u8 Parser
Other
248 stars 94 forks source link

Missing BOM tag (UTF-8 support incomplete) #18

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hi,

I created an playlist with this library and enabled the Encoding.UTF8 flag. This playlist works fine in Winamp, but Foobar isn't able to play the UTF8 paths.

After searching on the internet I found a topic talking about the BOM tag (first three bytes of the file: EF BB BF), I tested this with Foobar and it actually works!

Anyway, Am i missing some configuration option or is this missing from the library?

For reference: http://www.hydrogenaud.io/forums/index.php?showtopic=93905

Edit: I temporarily solved it using:

OutputStream outputStream = new FileOutputStream(fullPlayListPath);
PlaylistWriter writer = new PlaylistWriter();
outputStream.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
writer.write(outputStream, playlist, Format.EXT_M3U, Encoding.UTF_8);

Would ofcourse be nicer if the library would take care of this.

Wopple commented 9 years ago

Thank you for bringing this to my attention! There is currently no support for BOM parsing / writing in this library.

After briefly educating myself on the BOM character, I think it is suitable for this library to provide optional support where the default is to assume it is not present. The UTF-8 specification says that a BOM should be optional and its use is not recommended since byte order is irrelevant to UTF-8. The BOM character seems to be used as a marker that the stream is UTF-8 rather than indicating byte order. This is confusing and not something that should be supported by default IMHO.

I will add optional support for reading / writing and let you know when it is ready.

Wopple commented 9 years ago

@maikeldus I prepared PR #19 if you want to create your own snapshot build from the branch. I can't say exactly when a release will go out to Maven Central.

ghost commented 9 years ago

Thanks for the response! The issue is not critical so I will just wait for whenever the maven library gets updated. I have checked the merge request and the addition look good, I prefer the latest commit you provided.

I do still have another small question, do you know if it's possible to create m3u files (non-UTF8) that reference an UTF8 filename (with for example unicode usage in the filenames)? The default Android media implementation does not seem to support m3u8.

Thanks for sharing the code as a library btw ;)

Wopple commented 9 years ago

Are you asking if you can create windows-1252 encoded files with the .m3u8 extension? You can explicitly set the encoding you want this library to use when parsing (utf-8 or windows-1252) so the filename's extension is not taken into account.

Wopple commented 9 years ago

I just sent out a release for the 0.1.2 version. It may take a couple hours before it is publicly available. Please see if that works for you and then I can close this issue.

ghost commented 9 years ago

Sorry for the late response, it's working fine now. Thanks!

My question was about the default Android media implementation failing to parse UTF-8 playlist files, but I found a music player with a custom implementation.