Class: Media::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/media/container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, &block) ⇒ Container

Returns a new instance of Container.



12
13
14
15
16
17
18
# File 'lib/media/container.rb', line 12

def initialize(args, &block)
  @url   = args.fetch(:url) { raise ':url required'}
  @probe = args.fetch(:probe, Command::Probe)
  @options = args.fetch(:options, [])
  
  block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/media/container.rb', line 10

def url
  @url
end

Instance Method Details

#formatObject



27
28
29
# File 'lib/media/container.rb', line 27

def format
  OpenStruct.new(['format'])
end

#framesObject



36
37
38
39
40
# File 'lib/media/container.rb', line 36

def frames
  warn 'show_frames option required' unless ['frames']
  
  Array(['frames']).map {|s| OpenStruct.new(s)}
end

#metadataObject



42
43
44
# File 'lib/media/container.rb', line 42

def 
  @metadata ||= JSON.parse(probe.out)
end

#options(value = nil) ⇒ Object Also known as: options=



20
21
22
23
24
# File 'lib/media/container.rb', line 20

def options(value=nil)
  return @options + required_options unless value
    
  @options = value.map {|k,v| Option.new(key: k, value: v)}
end

#streams(type = /.*/) ⇒ Object



31
32
33
34
# File 'lib/media/container.rb', line 31

def streams(type=/.*/)      
  ['streams'].select {|s| s['codec_type'].match(type)}.
    map {|s| OpenStruct.new(s)}
end