Class: Zencoder::CLI::Command::Job

Inherits:
Base
  • Object
show all
Defined in:
lib/zencoder-cli/commands/jobs.rb

Class Method Summary collapse

Methods inherited from Base

extract_id, provides

Methods included from Helpers

#ask, #confirm, #display, #error, #format_date, #home_directory, #running_on_a_mac?, #running_on_windows?, #truncate

Class Method Details

.cancel(args, global_options, command_options) ⇒ Object



178
179
180
181
182
# File 'lib/zencoder-cli/commands/jobs.rb', line 178

def cancel(args, global_options, command_options)
  job_id = extract_id(args)
  response = Zencoder::Job.cancel(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli
  puts "Job ##{job_id} cancelled."
end

.delete(args, global_options, command_options) ⇒ Object



184
185
186
187
188
# File 'lib/zencoder-cli/commands/jobs.rb', line 184

def delete(args, global_options, command_options)
  job_id = extract_id(args)
  response = Zencoder::Job.delete(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli
  puts "Job ##{job_id} deleted."
end

.open(args, global_options, command_options) ⇒ Object



167
168
169
170
# File 'lib/zencoder-cli/commands/jobs.rb', line 167

def open(args, global_options, command_options)
  job_id = extract_id(args)
  `open https://app.zencoder.com/jobs/#{job_id}`
end

.resubmit(args, global_options, command_options) ⇒ Object



172
173
174
175
176
# File 'lib/zencoder-cli/commands/jobs.rb', line 172

def resubmit(args, global_options, command_options)
  job_id = extract_id(args)
  response = Zencoder::Job.resubmit(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli
  puts "Job ##{job_id} resubmitted."
end

.run(args, global_options, command_options) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/zencoder-cli/commands/jobs.rb', line 95

def run(args, global_options, command_options)
  job_id = extract_id(args)
  job = Zencoder::Job.details(job_id, :base_url => Zencoder.base_url(global_options[:environment])).process_for_cli.body["job"]
  rows = []
  rows << ["ID", job["id"]]
  rows << ["Created", format_date(job["created_at"])]
  rows << ["Finished", format_date(job["finished_at"])] if job["finished_at"]
  rows << ["Pass Through", job["pass_through"]] if job["pass_through"]
  rows << ["Test", job["test"] ? "YES" : "NO"]
  rows << ["State", job["state"].titleize]
  puts table([{ :value => "Job", :colspan => 2 }], *rows)
  puts

  input = job["input_media_file"]
  rows = []
  rows << ["ID", input["id"]]
  rows << ["URL", input["url"]]
  rows << ["State", input["state"].titleize]
  rows << ["Duration", (input["duration_in_ms"]/1000).to_s+" seconds"] if input["duration_in_ms"]
  rows << ["Size", ("%0.2f" % (input["file_size_bytes"].to_f/1.megabyte))+" MB"] if input["file_size_bytes"]
  rows << ["Format", input["format"]] if input["format"]
  if input["state"] == "finished"
    rows << :separator
    rows << ["Video Codec", input["video_codec"]] if input["video_codec"]
    rows << ["Resolution", input["width"].to_s+"x"+input["height"].to_s] if input["width"] && input["height"]
    rows << ["Video Bitrate", input["video_bitrate_in_kbps"].to_s+" Kbps"] if input["video_bitrate_in_kbps"]
    rows << ["Frame Rate", input["frame_rate"]] if input["frame_rate"]
    rows << :separator
    rows << ["Audio Codec", input["audio_codec"]] if input["audio_codec"]
    rows << ["Audio Bitrate", input["audio_bitrate_in_kbps"].to_s+" Kbps"] if input["audio_codec"]
    rows << ["Sample Rate", input["audio_sample_rate"]] if input["audio_sample_rate"]
    rows << ["Channels", input["channels"]] if input["channels"]
  end
  if input["error_class"] || input["error_message"]
    rows << :separator
    rows << ["Error Class", input["error_class"]] if input["error_class"]
    rows << ["Error Message", input["error_message"]] if input["error_message"]
  end
  puts table([{ :value => "Input", :colspan => 2 }], *rows)
  puts

  job["output_media_files"].each_with_index do |output, i|
    rows = []
    rows << ["ID", output["id"]]
    rows << ["Label", output["label"]] if output["label"]
    rows << ["URL", output["url"]]
    rows << ["State", output["state"].titleize]
    rows << ["Duration", (output["duration_in_ms"]/1000).to_s+" seconds"] if output["duration_in_ms"]
    rows << ["Size", ("%0.2f" % (output["file_size_bytes"].to_f/1.megabyte))+" MB"] if output["file_size_bytes"]
    rows << ["Format", output["format"]] if output["format"]
    if output["state"] == "finished"
      rows << :separator
      rows << ["Video Codec", output["video_codec"]] if output["video_codec"]
      rows << ["Resolution", output["width"].to_s+"x"+output["height"].to_s] if output["width"] && output["height"]
      rows << ["Video Bitrate", output["video_bitrate_in_kbps"].to_s+" Kbps"] if output["video_bitrate_in_kbps"]
      rows << ["Frame Rate", output["frame_rate"]] if output["frame_rate"]
      rows << :separator
      rows << ["Audio Codec", output["audio_codec"]] if output["audio_codec"]
      rows << ["Audio Bitrate", output["audio_bitrate_in_kbps"].to_s+" Kbps"] if output["audio_codec"]
      rows << ["Sample Rate", output["audio_sample_rate"]] if output["audio_sample_rate"]
      rows << ["Channels", output["channels"]] if output["channels"]
    end
    if output["error_class"] || output["error_message"]
      rows << :separator
      rows << ["Error Class", output["error_class"]] if output["error_class"]
      rows << ["Error Message", output["error_message"]] if output["error_message"]
    end
    puts table([{ :value => "Output ##{i+1}", :colspan => 2 }], *rows)
    puts
  end
end