lib/m3uzi/file.rb in m3uzi-0.2.1 vs lib/m3uzi/file.rb in m3uzi-0.4.2
- old
+ new
@@ -1,15 +1,41 @@
class M3Uzi
- class File
+ class File < Item
- attr_accessor :path, :duration, :description, :byterange
+ 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}"
+ "#{sprintf('%0.4f',duration)}," + description.to_s.gsub(/[\r\n]/,' ').strip
else
- "#{duration},#{description}"
+ "#{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