Class: VideoConverter::OpenSSL
Class Attribute Summary collapse
-
.bin ⇒ Object
Returns the value of attribute bin.
-
.command ⇒ Object
Returns the value of attribute command.
-
.encryption_type ⇒ Object
Returns the value of attribute encryption_type.
Class Method Summary collapse
- .get_encryption_key(output) ⇒ Object
- .get_encryption_key_path(output) ⇒ Object
- .run(output) ⇒ Object
Class Attribute Details
.bin ⇒ Object
Returns the value of attribute bin.
4 5 6 |
# File 'lib/video_converter/openssl.rb', line 4 def bin @bin end |
.command ⇒ Object
Returns the value of attribute command.
4 5 6 |
# File 'lib/video_converter/openssl.rb', line 4 def command @command end |
.encryption_type ⇒ Object
Returns the value of attribute encryption_type.
4 5 6 |
# File 'lib/video_converter/openssl.rb', line 4 def encryption_type @encryption_type end |
Class Method Details
.get_encryption_key(output) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/video_converter/openssl.rb', line 43 def self.get_encryption_key(output) if output.encryption_key File.join(output.work_dir, "video.key") elsif output.encryption_key_url File.join(output.work_dir, "url.video.key") else File.join(output.work_dir, "#{output.filename}.key") end end |
.get_encryption_key_path(output) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/video_converter/openssl.rb', line 29 def self.get_encryption_key_path(output) if output.encryption_key File.open(File.join(output.work_dir,'video.key'), 'wb') { |f| f.write output.encryption_key } 'video.key' elsif output.encryption_key_url uri = URI(output.encryption_key_url) File.open(File.join(output.work_dir,'url.video.key'), 'wb') { |f| f.puts Net::HTTP.get(uri.host, uri.path) } output.encryption_key_url else File.open(File.join(output.work_dir, "#{output.filename}.key"), 'wb') { |f| f.write SecureRandom.hex(8) } "#{output.filename}.key" end end |
.run(output) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/video_converter/openssl.rb', line 12 def self.run(output) success = true playlist = File.join(output.work_dir, output.filename) File.write(playlist, File.read(playlist).sub("#EXTM3U\n", "#EXTM3U\n#EXT-X-KEY:METHOD=AES-128,URI=\"#{OpenSSL.get_encryption_key_path(output)}\"\n")) encryption_dir = FileUtils.mkdir_p("#{output.chunks_dir}_encrypted").first chunks = Dir::glob(File.join(output.chunks_dir, "*.ts")).sort do |c1, c2| File.basename(c1).match(/\d+/).to_s.to_i <=> File.basename(c2).match(/\d+/).to_s.to_i end chunks.each_with_index do |chunk, index| initialization_vector = "%032x" % index success &&= Command.new(command, prepare_params( :chunk => chunk, :encrypted_chunk => File.join(encryption_dir,File.basename(chunk)), :initialization_vector => initialization_vector, :encryption_key => OpenSSL.get_encryption_key(output) )).execute end remove_old_dir(output) if success success end |