Module: Zencodable::InstanceMethods

Defined in:
lib/zencodable.rb

Instance Method Summary collapse

Instance Method Details

#create_jobObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zencodable.rb', line 44

def create_job
  if self.origin_url_changed?
    logger.debug "Origin URL changed. Creating new ZenCoder job."
    if @job = Encoder::Job.create(self)
      logger.debug "ZenCoder job created, ID = #{@job.id}"
      self.zencoder_job_id = @job.id
      self.zencoder_job_status = 'new'
      self.zencoder_job_created = Time.now
      self.zencoder_job_finished = nil
    end
  end
end

#job_statusObject



36
37
38
39
40
41
42
# File 'lib/zencodable.rb', line 36

def job_status
  unless ['finished','failed'].include? zencoder_job_status
    logger.debug "Unfinished job found. Updating details."
    update_job
  end
  self.zencoder_job_status
end

#source_file_for(fmt) ⇒ Object



69
70
71
# File 'lib/zencodable.rb', line 69

def source_file_for(fmt)
  self.video_files.where(:format => fmt).first
end

#update_jobObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/zencodable.rb', line 57

def update_job
  self.zencoder_job_status = encoder_job.status
  self.zencoder_job_finished = encoder_job.finished_at
  if encoded_files = encoder_job.files
    self.video_files = encoded_files.collect{ |file| video_files_class.new(file) }
  end
  if self.class.encoder_thumbnails_association && (encoded_thumbs = encoder_job.thumbnails)
    self.video_thumbnails = encoded_thumbs.collect{ |file| video_thumbnails_class.new(file) }
  end
  save
end

#video_filesObject



73
74
75
# File 'lib/zencodable.rb', line 73

def video_files
  self.send(video_files_method)
end

#video_files=(*args) ⇒ Object



81
82
83
# File 'lib/zencodable.rb', line 81

def video_files= *args
  self.send "#{video_files_method}=", *args
end

#video_thumbnailsObject



77
78
79
# File 'lib/zencodable.rb', line 77

def video_thumbnails
  self.send(video_files_thumbnails_method)
end

#video_thumbnails=(*args) ⇒ Object



85
86
87
# File 'lib/zencodable.rb', line 85

def video_thumbnails= *args
  self.send("#{video_files_thumbnails_method}=", *args) if video_files_thumbnails_method
end