Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request/bug: Support iTunes' m3u8 files #30

Open
Joshfindit opened this issue Jun 3, 2021 · 1 comment
Open

Request/bug: Support iTunes' m3u8 files #30

Joshfindit opened this issue Jun 3, 2021 · 1 comment

Comments

@Joshfindit
Copy link

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.

@Joshfindit Joshfindit changed the title Support "regular" m3u8 files? Request/bug: Support iTunes' m3u8 files Jun 3, 2021
@Joshfindit
Copy link
Author

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:

input.each_line.with_index do |line, index|

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant