Sha256: ffa3ffe348eb4060fca045e0e0e2583e2f7f1e7b073db72258813a3c71a15d23

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

class M3Uzi
  class File < Item

    attr_accessor :path, :duration, :description, :byterange, :byterange_offset, :encryption_key_url, :encryption_iv

    # Unsupported tags: PROGRAM-DATE-TIME, DISCONTINUITY, I-FRAMES-ONLY
    # Autogenerated tags: EXTINF, BYTERANGE, KEY, VERSION, TARGETDURATION, ENDLIST

    def initialize
      @encryption_key_url = :unset
    end

    def attribute_string
      if duration.kind_of?(Float)
        "#{sprintf('%0.4f',duration)}," + description.to_s.gsub(/[\r\n]/,' ').strip
      else
        "#{duration.to_i.round}," + description.to_s.gsub(/[\r\n]/,' ').strip
      end
    end

    def format
      # Need to add key info if appropriate?
      "#EXTINF:#{attribute_string}\n#{path}"
    end

    def encryption_iv=(value)
      if value.to_s =~ /^0x/i
        value = $'
      end

      if value.kind_of?(String)
        raise "Invalid encryption_iv given" unless value.length <= 32 && value =~ /^[0-9a-f]+$/i
        @encryption_iv = '0x' + value.downcase.rjust(32,'0')
      elsif value.nil?
        @encryption_iv = nil
      else
        @encryption_iv = M3Uzi.format_iv(value.to_i)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
m3uzi-0.5.1 lib/m3uzi/file.rb
m3uzi-0.5.0 lib/m3uzi/file.rb
m3uzi-0.4.3 lib/m3uzi/file.rb
m3uzi-0.4.2 lib/m3uzi/file.rb