Sha256: 381e9cd8c521ae379afe2f28827ba9943f4d9923b580ac1a24715d79a6b63cc5

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

require_relative 'keys_box'
require_relative 'ilst_box'
require_relative '../box_path'
require 'time'

module FileData
  # Parser for the 'meta' box
  class MetaBoxParser
    def self.parse(view)
      creation_key = get_creation_key(view)
      return MetaBox.new(nil) if creation_key.nil?

      creation_date_data = get_creation_date(view, creation_key.index)
      return MetaBox.new(nil) if creation_date_data.nil?

      MetaBox.new(Time.parse(creation_date_data.data_box.value_text))
    end

    def self.get_creation_key(view)
      kb = BoxPath.get_path(view, 'keys')
      return nil if kb.nil?

      keys = KeysBoxParser.parse(kb.content_stream)
      keys.find { |key| key.value == 'com.apple.quicktime.creationdate' }
    end

    def self.get_creation_date(view, index)
      ilst_boxes = get_ilst_boxes(view)
      ilst_boxes.find { |x| x.index == index }
    end

    def self.get_ilst_boxes(view)
      view.seek view.start_pos
      box = BoxPath.get_path(view, 'ilst')
      ilst_boxes = []
      ilst_boxes << IlstBoxParser.parse(box.content_stream) until box.content_stream.eof?
      ilst_boxes
    end
  end

  MetaBox = Struct.new(:creation_date)
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
file_data-6.0.0 lib/file_data/formats/mpeg4/box_parsers/meta_box.rb
file_data-5.2.3 lib/file_data/formats/mpeg4/box_parsers/meta_box.rb
file_data-5.2.2 lib/file_data/formats/mpeg4/box_parsers/meta_box.rb
file_data-5.2.1 lib/file_data/formats/mpeg4/box_parsers/meta_box.rb
file_data-5.2.0 lib/file_data/formats/mpeg4/box_parsers/meta_box.rb