Skip to content

Commit

Permalink
Merge c8cc27e into 0b263c0
Browse files Browse the repository at this point in the history
  • Loading branch information
tf committed Oct 20, 2016
2 parents 0b263c0 + c8cc27e commit c70487c
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 135 deletions.
2 changes: 1 addition & 1 deletion app/jobs/pageflow/poll_zencoder_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.fetch_thumbnail(file)
end

def self.fetch_input_details(file, api)
file.meta_data_attributes = api.get_input_details(file.job_id)
file.meta_data_attributes = api.get_details(file.job_id)
rescue ZencoderApi::RecoverableError => e
file.encoding_error_message = e.message
throw(:halt, :pending)
Expand Down
46 changes: 46 additions & 0 deletions app/models/concerns/pageflow/output_source.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Pageflow
module OutputSource
STATE_MAPPING = {
true => 'finished',
false => 'skipped'
}.freeze

extend ActiveSupport::Concern

included do
serialize :output_presences, JSON
end

def present_outputs
present_outputs_label_state_array = output_presences.select do |output_label, _output_state|
output_present?(output_label) == true
end

present_outputs_label_state_array.map { |output_label_state| output_label_state[0].to_sym }
end

def output_present?(type)
output_presences[type.to_s]
end

def output_presences=(presences)
boolean_presences = presences.stringify_keys.each_with_object({}) do |(key, value), result|
if value == true || value == STATE_MAPPING[true]
result[key] = true
elsif value == false || value == STATE_MAPPING[false]
result[key] = false
elsif value.blank?
result[key] = nil
end
end

self[:output_presences] = output_presences
.merge(boolean_presences)
.reject { |_key, value| value.nil? }
end

def output_presences
super || {}
end
end
end
15 changes: 14 additions & 1 deletion app/models/pageflow/video_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Pageflow
class VideoFile < ActiveRecord::Base
include HostedFile
include EncodedFileStateMachine
include OutputSource

belongs_to :confirmed_by, :class_name => 'User'

Expand Down Expand Up @@ -50,6 +51,14 @@ def webm_medium
end


def mp4_4k
ZencoderAttachment.new(self, "4k.mp4")
end

def mp4_fullhd
ZencoderAttachment.new(self, "fullhd.mp4")
end

def mp4_high
ZencoderAttachment.new(self, "high.mp4")
end
Expand Down Expand Up @@ -102,7 +111,11 @@ def output_definition
end

def meta_data_attributes=(attributes)
self.attributes = attributes.symbolize_keys.slice(:format, :duration_in_ms, :width, :height)
self.attributes = attributes.symbolize_keys.slice(:format,
:duration_in_ms,
:width,
:height,
:output_presences)
end
end
end
1 change: 1 addition & 0 deletions config/initializers/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

config.features.register('auto_change_page')
config.features.register('delayed_text_fade_in')
config.features.register('highdef_video_encoding')
config.features.register('storylines') do |feature_config|
feature_config.help_entries.register('pageflow.help_entries.storylines', priority: 7)
end
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/zencoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Pageflow::ZencoderOutputDefinition.default_akamai_host = zencoder_options[:akamai_host]
Pageflow::ZencoderOutputDefinition.default_akamai_credentials = zencoder_options[:akamai_credentials]
Pageflow::ZencoderVideoOutputDefinition.skip_hls = zencoder_options.fetch(:skip_hls, false)
Pageflow::ZencoderVideoOutputDefinition.skip_smil = zencoder_options.fetch(:skip_hls, false)
Pageflow::ZencoderVideoOutputDefinition.skip_smil = zencoder_options.fetch(:skip_smil, false)

raise "Missing s3_host_alias option in Pageflow.config.zencoder_options." unless zencoder_options.has_key?(:s3_host_alias)
raise "Missing s3_protocol option in Pageflow.config.zencoder_options." unless zencoder_options.has_key?(:s3_protocol)
Expand Down
4 changes: 4 additions & 0 deletions config/locales/new/highdef_video_encoding.de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
de:
pageflow:
highdef_video_encoding:
feature_name: "Full HD und 4K Videos"
4 changes: 4 additions & 0 deletions config/locales/new/highdef_video_encoding.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
pageflow:
highdef_video_encoding:
feature_name: "Full HD and 4K videos"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddOutputPresencesToVideoFiles < ActiveRecord::Migration
def change
add_column :pageflow_video_files, :output_presences, :text
end
end
22 changes: 18 additions & 4 deletions lib/pageflow/zencoder_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,32 @@ def get_info(job_id)
end
end

# @deprecated Use `get_details(job_id)` instead.
def get_input_details(job_id)
get_details(job_id)
end

def get_details(job_id)
with_exception_translation do
response = Zencoder::Job.details(job_id)

if response.success?
input_details = response.body['job']['input_media_file']
outputs_details = response.body['job']['output_media_files']

output_presences = outputs_details.inject({}) do |presences, output|
if output['label'].present?
presences[output['label'].to_sym] = output['state']
end
presences
end

{
:format => input_details["format"],
:duration_in_ms => input_details["duration_in_ms"],
:width => input_details["width"],
:height => input_details["height"]
format: input_details['format'],
duration_in_ms: input_details['duration_in_ms'],
width: input_details['width'],
height: input_details['height'],
output_presences: output_presences
}
else
raise translate_zencoder_errors(response.errors)
Expand Down
Loading

0 comments on commit c70487c

Please sign in to comment.