Class: F4M
- Inherits:
-
Object
- Object
- F4M
- Defined in:
- lib/glued/f4m.rb
Constant Summary collapse
- NAMESPACE =
'http://ns.adobe.com/f4m/1.0'
Instance Attribute Summary collapse
-
#base_ref ⇒ Object
readonly
Returns the value of attribute base_ref.
-
#bootstrap_info ⇒ Object
readonly
Returns the value of attribute bootstrap_info.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#media ⇒ Object
readonly
Returns the value of attribute media.
-
#media_filename ⇒ Object
readonly
Returns the value of attribute media_filename.
Instance Method Summary collapse
- #find_highest_bitrate(list) ⇒ Object
-
#initialize(url, data) ⇒ F4M
constructor
A new instance of F4M.
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_ref ⇒ Object (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_info ⇒ Object (readonly)
Returns the value of attribute bootstrap_info.
6 7 8 |
# File 'lib/glued/f4m.rb', line 6 def bootstrap_info @bootstrap_info end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
6 7 8 |
# File 'lib/glued/f4m.rb', line 6 def duration @duration end |
#media ⇒ Object (readonly)
Returns the value of attribute media.
6 7 8 |
# File 'lib/glued/f4m.rb', line 6 def media @media end |
#media_filename ⇒ Object (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 |