Request/bug: Support iTunes' m3u8 files
Such as the files that iTunes outputs when exporting playlists.
It's understandable (and clearly necessary) to have a library that handles HLS m3u8 files, it would just also be nice to import these other standard files.
Found the issue:
For some reason that I could not reasonably agree with, iTunes exports m3u8 files with \r as line terminators.
Ruby then sees only one line, and m3u8 sees 0 tracks.
Thankfully there is a way to have the read function use \r as the separator:
https://github.com/sethdeckard/m3u8/blob/b19e9053907665a5cf3cd1e3b85ca22b3581ca0c/lib/m3u8/reader.rb#L18
Could be file.read.each_line(sep="\r").with_index do |line, index|, but sep does not seem to take multiple optional line endings and each_line does not seem to be able to intelligently choose the line separator itself.
Cary Swoveland posted this function to find the line terminator, and that found terminator could be used as the sep value:
def separator(fname)
f = File.open(fname)
enum = f.each_char
c = enum.next
loop do
case c[/\r|\n/]
when "\n" then break
when "\r"
c << "\n" if enum.peek=="\n"
break
end
c = enum.next
end
c[0][/\r|\n/] ? c : "\n"
end
Or, the function could be changed so that the entire file is read in to memory and then .split since .split does take multiple optional line endings:
input.read.split(/\r?\n|\r\n?/).each_with_index do |line, index|
If any of those solutions is reasonable, just reply "Yes" with which one you want, and I'll put in a PR for it.