Class: Alula::Zencoder

Inherits:
VideoProcessor show all
Defined in:
lib/alula/processors/zencoder.rb

Instance Attribute Summary

Attributes inherited from Processor

#attachments, #item, #options, #site

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VideoProcessor

#process

Methods inherited from Processor

#asset_path, #info, mimetype, #process, process?

Constructor Details

#initialize(item, opts) ⇒ Zencoder

Returns a new instance of Zencoder.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/alula/processors/zencoder.rb', line 14

def initialize(item, opts)
  super
  
  @@lock.synchronize do
    ::Zencoder.api_key = options.token
    @s3 = ::AWS::S3.new({
      :access_key_id     => options.key_id,
      :secret_access_key => options.access_key,
    })
  end
end

Class Method Details

.available?(options) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/alula/processors/zencoder.rb', line 10

def self.available?(options)
  options.has_key?("token") and options.has_key?("key_id") and options.has_key?("access_key")
end

Instance Method Details

#cleanupObject



26
27
28
29
30
31
32
33
# File 'lib/alula/processors/zencoder.rb', line 26

def cleanup
  super
  
  @s3 = nil
  @bucket = nil
  @object = nil
  ::Zencoder.api_key = nil
end

#encode(variants, thumbnails) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/alula/processors/zencoder.rb', line 35

def encode(variants, thumbnails)
  return if variants.empty? and thumbnails.empty?
  
  @variants = variants
  @thumbnails = thumbnails
  
  # Upload attachment to S3 bucket
  upload_item unless item_uploaded
  
  # Create encoding profiles
  job = {input: "s3://#{@bucket.name}/#{@object.key}", outputs: [], test: !!self.site.config.testing}
  
  profiles.each { |name, profile| job[:outputs] << profile }
  
  job = zencoder_encode(job)
  success = zencoder_download(job)
end