Class: Falcon::Media
- Inherits:
-
Object
- Object
- Falcon::Media
- Defined in:
- lib/falcon/media.rb
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#all_ready? ⇒ Boolean
Check if source encoded by all profiles.
- #assign(source) ⇒ Object
-
#destroy ⇒ Object
Destroy files end encodings.
-
#dirty? ⇒ Boolean
Returns true if there are changes that need to be saved.
-
#exist? ⇒ Boolean
Check if source file exists.
-
#initialize(name, instance, options = {}) ⇒ Media
constructor
A new instance of Media.
-
#metadata ⇒ Object
A hash of metadatas for video:.
- #output_directory ⇒ Object
-
#path(profile) ⇒ Object
Returns the path of the generated media file by profile object or profile name.
-
#profiles ⇒ Object
Array of processing profiles.
- #ready?(profile) ⇒ Boolean
- #save ⇒ Object
-
#screenshots(&block) ⇒ Object
Yield generated screenshots and remove them.
-
#source_path ⇒ Object
Path for media source file.
-
#sources ⇒ Object
List of generated video files.
-
#url(profile) ⇒ Object
Returns the public URL of the media, with a given profile.
Constructor Details
#initialize(name, instance, options = {}) ⇒ Media
Returns a new instance of Media.
16 17 18 19 20 21 22 23 |
# File 'lib/falcon/media.rb', line 16 def initialize(name, instance, = {}) @name = name @instance = instance @options = self.class..merge() @profiles = @options[:profiles] @encode = @options[:encode] @dirty = false end |
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
14 15 16 |
# File 'lib/falcon/media.rb', line 14 def instance @instance end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/falcon/media.rb', line 14 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/falcon/media.rb', line 14 def @options end |
Class Method Details
.default_options ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/falcon/media.rb', line 5 def self. @default_options ||= { :profiles => ['web_mp4', 'web_ogg'], :metadata => {}, :source => nil, :encode => nil } end |
Instance Method Details
#all_ready? ⇒ Boolean
Check if source encoded by all profiles
101 102 103 |
# File 'lib/falcon/media.rb', line 101 def all_ready? instance.falcon_encodings.success.count == profiles.keys.size end |
#assign(source) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/falcon/media.rb', line 109 def assign(source) if File.exist?(source) @source_path = source @dirty = true end end |
#destroy ⇒ Object
Destroy files end encodings
89 90 91 92 93 |
# File 'lib/falcon/media.rb', line 89 def destroy flush_deletes @dirty = false true end |
#dirty? ⇒ Boolean
Returns true if there are changes that need to be saved.
67 68 69 |
# File 'lib/falcon/media.rb', line 67 def dirty? @dirty end |
#exist? ⇒ Boolean
Check if source file exists
96 97 98 |
# File 'lib/falcon/media.rb', line 96 def exist? File.exist?(source_path) end |
#metadata ⇒ Object
A hash of metadatas for video:
{ :title => ”, :author => ”, :copyright => ”,
:comment => '', :description => '', :language => ''}
47 48 49 50 51 52 |
# File 'lib/falcon/media.rb', line 47 def @metadata ||= begin method = @options[:metadata] method.respond_to?(:call) ? method.call(self) : instance.send(method) end end |
#output_directory ⇒ Object
62 63 64 |
# File 'lib/falcon/media.rb', line 62 def output_directory @output_directory ||= File.dirname(source_path) end |
#path(profile) ⇒ Object
Returns the path of the generated media file by profile object or profile name
72 73 74 |
# File 'lib/falcon/media.rb', line 72 def path(profile) Falcon::Profile.detect(profile).path(source_path, name) end |
#profiles ⇒ Object
Array of processing profiles
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/falcon/media.rb', line 26 def profiles unless @normalized_profiles @normalized_profiles = {} (@profiles.respond_to?(:call) ? @profiles.call(self) : @profiles).each do |name| @normalized_profiles[name] = Falcon::Profile.find(name) end end @normalized_profiles end |
#ready?(profile) ⇒ Boolean
105 106 107 |
# File 'lib/falcon/media.rb', line 105 def ready?(profile) instance.falcon_encodings.with_profile(profile).success.exists? end |
#save ⇒ Object
81 82 83 84 85 86 |
# File 'lib/falcon/media.rb', line 81 def save flush_deletes create_encodings @dirty = false true end |
#screenshots(&block) ⇒ Object
Yield generated screenshots and remove them
117 118 119 120 121 122 |
# File 'lib/falcon/media.rb', line 117 def screenshots(&block) Dir.glob("#{output_directory}/*.{jpg,JPG}").each do |filepath| yield filepath FileUtils.rm(filepath, :force => true) end end |
#source_path ⇒ Object
Path for media source file
55 56 57 58 59 60 |
# File 'lib/falcon/media.rb', line 55 def source_path @source_path ||= begin method = [:source] method.respond_to?(:call) ? method.call(instance) : instance.send(method) end end |
#sources ⇒ Object
List of generated video files
38 39 40 |
# File 'lib/falcon/media.rb', line 38 def sources @sources ||= profiles.values.map{|profile| url(profile) } end |
#url(profile) ⇒ Object
Returns the public URL of the media, with a given profile
77 78 79 |
# File 'lib/falcon/media.rb', line 77 def url(profile) "/" + path(profile).relative_path_from( Rails.root.join('public') ) end |