Class: F4M

Inherits:
Object
  • Object
show all
Defined in:
lib/glued/f4m.rb

Constant Summary collapse

NAMESPACE =
'http://ns.adobe.com/f4m/1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, data) ⇒ F4M

Returns a new instance of F4M.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/glued/f4m.rb', line 12

def initialize(url, data)
  xml = Nokogiri::XML(data)

  namespace = xml.root.namespace.href rescue 'not found'
  raise "Invalid manifest namespace. It was #{namespace} but should have been #{NAMESPACE}" unless namespace == NAMESPACE

  xml.remove_namespaces!

  stream_type = xml.xpath("//streamType").first.text rescue 'unknown'
  raise "Only recorded streams are supported." unless stream_type == 'recorded'

  @duration = xml.xpath("//duration").first.text.to_i

  b64_bootstrap_info = xml.xpath("//bootstrapInfo").first.text
  @bootstrap_info = Base64.strict_decode64(b64_bootstrap_info)

  media_nodes = xml.xpath("/manifest[1]/media")
  @media = find_highest_bitrate(media_nodes)
  @media_filename = @media.at_css('@url').value

  @base_ref = url.split('/').slice(0...-1).join('/') #can be specified in xml
end

Instance Attribute Details

#base_refObject (readonly)

Returns the value of attribute base_ref.



6
7
8
# File 'lib/glued/f4m.rb', line 6

def base_ref
  @base_ref
end

#bootstrap_infoObject (readonly)

Returns the value of attribute bootstrap_info.



6
7
8
# File 'lib/glued/f4m.rb', line 6

def bootstrap_info
  @bootstrap_info
end

#durationObject (readonly)

Returns the value of attribute duration.



6
7
8
# File 'lib/glued/f4m.rb', line 6

def duration
  @duration
end

#mediaObject (readonly)

Returns the value of attribute media.



6
7
8
# File 'lib/glued/f4m.rb', line 6

def media
  @media
end

#media_filenameObject (readonly)

Returns the value of attribute media_filename.



6
7
8
# File 'lib/glued/f4m.rb', line 6

def media_filename
  @media_filename
end

Instance Method Details

#find_highest_bitrate(list) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/glued/f4m.rb', line 35

def find_highest_bitrate(list)
  rates = []
  list.each do |media|
    br = media.at_css("@bitrate").value.to_i
    rates[br] = media
  end

  rates.reject {|e| e.nil? }.pop
end