<commit_before>$:<< File.dirname(__FILE__)
require 'm3uzi/item'
require 'm3uzi/tag'
require 'm3uzi/file'
require 'm3uzi/stream'
require 'm3uzi/comment'
require 'm3uzi/version'

class M3Uzi

  attr_accessor :header_tags, :playlist_items
  attr_accessor :playlist_type, :final_media_file
  attr_accessor :version, :initial_media_sequence, :sliding_window_duration

  def initialize
    @header_tags = {}
    @playlist_items = []
    @final_media_file = true
    @version = 1
    @initial_media_sequence = 0
    @sliding_window_duration = nil
    @removed_file_count = 0
    @playlist_type = :live
  end


  #-------------------------------------
  # Read/Write M3U8 Files
  #-------------------------------------

  ##
  ## For now, reading m3u8 files is not keeping up to date with writing, so we're
  ## disabling it in this version.  (Possibly to be re-introduced in the future.)
  ##
  def self.read(path)
    m3u = self.new

    lines = ::File.readlines(path)

    lines.each_with_index do |line, i|
      case type(line)
      when :tag
        name, value = parse_general_tag(line)
        m3u.add_tag do |tag|
          tag.name = name
          tag.value = value
        end
      when :info
        duration, description = parse_file_tag(line)
        m3u.add_file do |file|
          file.path = lines[i+1].strip
          file.duration = duration
          file.description = description
        end
        m3u.final_media_file = false
      when :stream
        attributes = parse_stream_tag(line)
        m3u.add_stream do |stream|
          stream.path = lines[i+1].strip
          attributes.each_pair do |k,v|
            k = k.to_s.downcase.sub('-','_')
            next unless [:bandwidth, :program_id, :codecs, :resolution].include?(k)
            v = $1 if v.to_s =~ /^"(.*)"$/
            stream.send("#{k}=", v)
          end
        end
      when :final
        m3u.final_media_file = true
      else
        next
      end
    end

    m3u
  end

  def write_to_io(io_stream)
    reset_encryption_key_history
    reset_byterange_history
<commit_msg>Fix up attributes call<commit_after>$:<< File.dirname(__FILE__)
require 'm3uzi/item'
require 'm3uzi/tag'
require 'm3uzi/file'
require 'm3uzi/stream'
require 'm3uzi/comment'
require 'm3uzi/version'

class M3Uzi

  attr_accessor :header_tags, :playlist_items
  attr_accessor :playlist_type, :final_media_file
  attr_accessor :version, :initial_media_sequence, :sliding_window_duration

  def initialize
    @header_tags = {}
    @playlist_items = []
    @final_media_file = true
    @version = 1
    @initial_media_sequence = 0
    @sliding_window_duration = nil
    @removed_file_count = 0
    @playlist_type = :live
  end


  #-------------------------------------
  # Read/Write M3U8 Files
  #-------------------------------------

  ##
  ## For now, reading m3u8 files is not keeping up to date with writing, so we're
  ## disabling it in this version.  (Possibly to be re-introduced in the future.)
  ##
  def self.read(path)
    m3u = self.new

    lines = ::File.readlines(path)

    lines.each_with_index do |line, i|
      case type(line)
      when :tag
        name, value = parse_general_tag(line)
        m3u.add_tag do |tag|
          tag.name = name
          tag.value = value
        end
      when :info
        duration, description = parse_file_tag(line)
        m3u.add_file do |file|
          file.path = lines[i+1].strip
          file.duration = duration
          file.description = description
        end
        m3u.final_media_file = false
      when :stream
        attributes = parse_stream_tag(line)
        m3u.add_stream do |stream|
          stream.path = lines[i+1].strip
          attributes.to_h.each do |k,v|
            k = k.to_s.downcase.sub('-','_')
            next unless [:bandwidth, :program_id, :codecs, :resolution].include?(k)
            v = $1 if v.to_s =~ /^"(.*)"$/
            stream.send("#{k}=", v)
          end
        end
      when :final
        m3u.final_media_file = true
      else
        next
      end
    end

    m3u
  end

  def write_to_io(io_stream)
    reset_encryption_key_history
    reset_byterange_history

{'fraction_non_alphanumeric': 0.13254751022371902, 'fraction_numerical': 0.01154678854943469, 'mean_word_length': 2.086859688195991, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1008780', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1367, 'n_words': 317}