class ActiveEncode::EngineAdapters::ZencoderAdapter
Public Instance Methods
cancel(encode)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 19 def cancel(encode) response = Zencoder::Job.cancel(encode.id) if response.success? build_encode(get_job_details(encode.id), encode.class) else nil end end
create(encode)
click to toggle source
TODO add a stub for an input helper (supplied by an initializer) that transforms encode.input into a zencoder accepted url
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 6 def create(encode) response = Zencoder::Job.create(:input => "#{encode.input}") build_encode(get_job_details(response.body["id"]), encode.class) end
find(id, opts = {})
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 11 def find(id, opts = {}) build_encode(get_job_details(id), opts[:cast]) end
list(*filters)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 15 def list(*filters) raise NotImplementedError end
purge(encode)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 28 def purge(encode) raise NotImplementedError end
remove_output(encode, output_id)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 32 def remove_output(encode, output_id) raise NotImplementedError end
Private Instance Methods
build_encode(job_details, cast)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 45 def build_encode(job_details, cast) return nil if job_details.nil? encode = cast.new(convert_input(job_details), convert_options(job_details)) encode.id = job_details.body["job"]["id"].to_s encode.state = convert_state(job_details) job_progress = get_job_progress(encode.id) encode.current_operations = convert_current_operations(job_progress) encode.percent_complete = convert_percent_complete(job_progress, job_details) encode.output = convert_output(job_details) encode.errors = convert_errors(job_details) encode.tech_metadata = convert_tech_metadata(job_details.body["job"]["input_media_file"]) encode end
convert_current_operations(job_progress)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 72 def convert_current_operations(job_progress) current_ops = [] job_progress.body["outputs"].each {|output| current_ops << output["current_event"] unless output["current_event"].nil?} current_ops end
convert_errors(job_details)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 104 def convert_errors(job_details) errors = [] input_error = job_details.body["job"]["input_media_file"]["error_message"] errors << input_error unless input_error.blank? job_details.body["job"]["output_media_files"].each {|o| errors << o["error_message"] unless o["error_message"].blank?} errors end
convert_input(job_details)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 85 def convert_input(job_details) job_details.body["job"]["input_media_file"]["url"] end
convert_options(job_details)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 89 def convert_options(job_details) {} end
convert_output(job_details)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 93 def convert_output(job_details) output = [] job_details.body["job"]["output_media_files"].each do |o| track_id = o["id"].to_s label = o["label"] url = o["url"] output << convert_tech_metadata(o).merge({id: track_id, url: url, label: label}) end output end
convert_percent_complete(job_progress, job_details)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 78 def convert_percent_complete(job_progress, job_details) percent = job_progress.body["progress"] percent ||= 100 if convert_state(job_details) == :completed percent ||= 0 percent end
convert_state(job_details)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 59 def convert_state(job_details) case job_details.body["job"]["state"] when "pending", "waiting", "processing" #Should there be a queued state? :running when "cancelled" :cancelled when "failed" :failed when "finished" :completed end end
convert_tech_metadata(media_file)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 112 def convert_tech_metadata(media_file) return {} if media_file.nil? metadata = {} media_file.each_pair do |key, value| next if value.blank? case key when "md5_checksum" metadata[:checksum] = value when "format" metadata[:mime_type] = value when "duration_in_ms" metadata[:duration] = value.to_s when "audio_codec" metadata[:audio_codec] = value.to_s when "channels" metadata[:audio_channels] = value.to_s when "audio_bitrate_in_kbps" metadata[:audio_bitrate] = value.to_s when "video_codec" metadata[:video_codec] = value when "frame_rate" metadata[:video_framerate] = value.to_s when "video_bitrate_in_kbps" metadata[:video_bitrate] = value.to_s when "width" metadata[:width] = value.to_s when "height" metadata[:height] = value.to_s end end metadata end
get_job_details(job_id)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 37 def get_job_details(job_id) Zencoder::Job.details(job_id) end
get_job_progress(job_id)
click to toggle source
# File lib/active_encode/engine_adapters/zencoder_adapter.rb, line 41 def get_job_progress(job_id) Zencoder::Job.progress(job_id) end