Class: Video

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/forge/app/models/video.rb

Instance Method Summary collapse

Instance Method Details

#encode(rails_env) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/forge/app/models/video.rb', line 37

def encode(rails_env)
  test = rails_env == "production" ? false : true
  response = Zencoder::Job.create({
    :api_key => Forge.config.videos.zencoder_api_key,
    :input => video.url,
    :outputs => [web_encode_settings, mobile_encode_settings, thumbnail_settings],
    :test => test,
    :skip_ssl_verify => test
  })
  self.update_attributes(:encoded_state => "queued", :mobile_encoded_state => "queued", :job_id => response.body["id"]) if response.success?
  response
end

#encode_notify(output) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/forge/app/models/video.rb', line 50

def encode_notify(output)
  prefix = output[:label] == "web" ? "" : "#{output[:label]}_"
  attrs = {"#{prefix}encoded_state" => output[:state]}
  if output[:state] == "finished"
    thumb = open(URI.parse("http://s3.amazonaws.com/" + Forge.config.videos.zencoder_bucket + "/thumbnails_#{id}/frame_0000.png"))
    attrs.merge!({"#{prefix}output_url" => output[:url]})
    attrs.merge!({"thumbnail" => thumb}) if thumbnail.url.blank?
  end
  self.update_attributes(attrs)
end

#encoded_stateObject



29
30
31
# File 'lib/forge/app/models/video.rb', line 29

def encoded_state
  read_attribute(:encoded_state) || "unencoded"
end

#list_titleObject



25
26
27
# File 'lib/forge/app/models/video.rb', line 25

def list_title
  published ? title : title + " (Draft)"
end

#mobile_encoded_stateObject



33
34
35
# File 'lib/forge/app/models/video.rb', line 33

def mobile_encoded_state
  read_attribute(:mobile_encoded_state) || "unencoded"
end

#video=(filename) ⇒ Object



21
22
23
# File 'lib/forge/app/models/video.rb', line 21

def video=(filename)
  self.video_file_name = filename.gsub('videos/', '')
end