Class: Aspera::Preview::Generator
- Inherits:
-
Object
- Object
- Aspera::Preview::Generator
- Defined in:
- lib/aspera/preview/generator.rb
Overview
generate one preview file for one format for one file at a time
Constant Summary collapse
- PREVIEW_FORMATS =
values for preview_format : output format
[:png,:mp4]
Instance Attribute Summary collapse
-
#conversion_type ⇒ Object
readonly
CLI needs to know conversion type to know if need skip it.
Instance Method Summary collapse
-
#generate ⇒ Object
create preview as specified in constructor.
-
#initialize(options, src, dst, main_temp_dir, api_mime_type = nil, try_local_mime = true) ⇒ Generator
constructor
node API mime types are from: svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types supported preview type is one of Preview::PREVIEW_FORMATS the resulting preview file type is taken from destination file extension.
-
#processing_method_symb ⇒ Object
name of processing method in this object combination of: conversion type and output format (and video_conversion for video).
-
#supported? ⇒ Boolean
for instance, plaintext to mp4 is not supported.
Constructor Details
#initialize(options, src, dst, main_temp_dir, api_mime_type = nil, try_local_mime = true) ⇒ Generator
node API mime types are from: svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types supported preview type is one of Preview::PREVIEW_FORMATS the resulting preview file type is taken from destination file extension. conversion methods are provided by private methods: convert_<conversion_type>to<preview_format> (combi = combination of source file type and destination format)
-> conversion_type is one of FileTypes::CONVERSION_TYPES
-> preview_format is one of Generator::PREVIEW_FORMATS
the conversion video->mp4 is implemented in methods: convert_video_to_mp4_using_<video_conversion>
-> conversion method is one of Generator::VIDEO_CONVERSION_METHODS
28 29 30 31 32 33 34 35 36 |
# File 'lib/aspera/preview/generator.rb', line 28 def initialize(,src,dst,main_temp_dir,api_mime_type=nil,try_local_mime=true) = @source_file_path=src @destination_file_path=dst @temp_folder=File.join(main_temp_dir,@source_file_path.split('/').last.gsub(/\s/, '_').gsub(/\W/, '')) # extract preview format from extension of target file @preview_format_symb=File.extname(@destination_file_path).gsub(/^\./,'').to_sym @conversion_type=FileTypes.conversion_type(@source_file_path,api_mime_type,try_local_mime) end |
Instance Attribute Details
#conversion_type ⇒ Object (readonly)
CLI needs to know conversion type to know if need skip it
14 15 16 |
# File 'lib/aspera/preview/generator.rb', line 14 def conversion_type @conversion_type end |
Instance Method Details
#generate ⇒ Object
create preview as specified in constructor
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/aspera/preview/generator.rb', line 62 def generate raise "could not detect type of file" if @conversion_type.nil? method_symb=processing_method_symb Log.log.info("#{@source_file_path}->#{@destination_file_path} (#{method_symb})") begin self.send(method_symb) # check that generated size does not exceed maximum result_size=File.size(@destination_file_path) if result_size > .max_size Log.log.warn("preview size exceeds maximum #{result_size} > #{@options.max_size}") end rescue => e Log.log.error("#{e.message}") Log.log.debug(e.backtrace.join("\n").red) FileUtils.cp(File.(@preview_format_symb.eql?(:mp4)?'video_error.png':'image_error.png',File.dirname(__FILE__)),@destination_file_path) ensure FileUtils.rm_rf(@temp_folder) end end |
#processing_method_symb ⇒ Object
name of processing method in this object combination of: conversion type and output format (and video_conversion for video)
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/aspera/preview/generator.rb', line 40 def processing_method_symb name="convert_#{@conversion_type}_to_#{@preview_format_symb}" if @conversion_type.eql?(:video) case @preview_format_symb when :mp4 name="#{name}_using_#{@options.video_conversion}" when :png name="#{name}_using_#{@options.video_png_conv}" end end Log.log.debug("method: #{name}") return name.to_sym end |
#supported? ⇒ Boolean
for instance, plaintext to mp4 is not supported
56 57 58 59 |
# File 'lib/aspera/preview/generator.rb', line 56 def supported? return false if @conversion_type.nil? return respond_to?(processing_method_symb,true) end |