Module: Hydra::Derivatives

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern, Deprecation
Defined in:
lib/hydra/derivatives.rb,
lib/hydra/derivatives/audio.rb,
lib/hydra/derivatives/image.rb,
lib/hydra/derivatives/video.rb,
lib/hydra/derivatives/config.rb,
lib/hydra/derivatives/ffmpeg.rb,
lib/hydra/derivatives/logger.rb,
lib/hydra/derivatives/document.rb,
lib/hydra/derivatives/processor.rb,
lib/hydra/derivatives/raw_image.rb,
lib/hydra/derivatives/io_decorator.rb,
lib/hydra/derivatives/jpeg2k_image.rb,
lib/hydra/derivatives/video/processor.rb,
lib/hydra/derivatives/extract_metadata.rb,
lib/hydra/derivatives/shell_based_processor.rb,
lib/hydra/derivatives/services/tempfile_service.rb,
lib/hydra/derivatives/services/persist_output_file_service.rb,
lib/hydra/derivatives/services/retrieve_source_file_service.rb,
lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb

Defined Under Namespace

Modules: ClassMethods, ExtractMetadata, Ffmpeg, ShellBasedProcessor, Video Classes: Audio, Config, Document, Image, IoDecorator, Jpeg2kImage, Logger, PersistBasicContainedOutputFileService, PersistOutputFileService, Processor, RawImage, RetrieveSourceFileService, TempfileService, TimeoutError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject



36
37
38
# File 'lib/hydra/derivatives.rb', line 36

def self.config
  @config ||= reset_config!
end

.reset_config!Object



40
41
42
# File 'lib/hydra/derivatives.rb', line 40

def self.reset_config!
  @config = Config.new
end

Instance Method Details

#constantize_processor(processor) ⇒ Object



116
117
118
119
120
# File 'lib/hydra/derivatives.rb', line 116

def constantize_processor(processor)
  "Hydra::Derivatives::#{processor.classify}".constantize
rescue NameError
  processor.classify.constantize
end

#create_derivativesObject

Runs all of the transformations immediately. You may want to run this job in the background as it may take a long time.



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/hydra/derivatives.rb', line 62

def create_derivatives
  if transformation_schemes.present?
    transformation_schemes.each do |transform_scheme|
      if transform_scheme.instance_of?(Proc)
        transform_scheme.call(self)
      else
        send(transform_scheme)
      end
    end
  else
    logger.warn "`create_derivatives' was called on an instance of #{self.class}, but no derivatives have been requested"
  end
end

#processor_class(processor) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/hydra/derivatives.rb', line 107

def processor_class(processor)
  case processor
    when :video
      Hydra::Derivatives::Video::Processor
    else
      constantize_processor(processor.to_s)
    end
end

#transform_datastream(file_name, transform_directives, opts = {}) ⇒ Object



122
123
124
# File 'lib/hydra/derivatives.rb', line 122

def transform_datastream(file_name, transform_directives, opts={})
  transform_file(file_name, transform_directives, opts={})
end

#transform_file(file_name, transform_directives, opts = {}) ⇒ Object

Create derivatives from a file according to transformation directives

Examples:

This will create content_thumb

transform_file :content, { :thumb => "100x100>" }

Specify the dsid for the output file

transform_file :content, { :thumb => {size: "200x300>", datastream: 'thumbnail'} }

Create multiple derivatives with one set of directives. This will create content_thumb and content_medium

transform_file :content, { :medium => "300x300>", :thumb => "100x100>" }

Specify which processor you want to use (defaults to :image)

transform_file :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
transform_file :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video

Specify an output file service to use when persisting generated derivatives

obj.transform_file :content, { mp4: { format: 'mp4' } }, processor: :video, output_file_service: My::System::PersistOutputFileToTapeStorage

Specify a source file service to use when retrieving the source

obj.transform_file :content, { mp4: { format: 'mp4' } }, processor: :video, source_file_service: My::System::PersistOutputFileToTapeStorage

Parameters:

  • file_name
  • transform_directives (Hash)
    • each key corresponds to a desired derivative. Associated values vary according to processor being used.

  • opts (Hash) (defaults to: {})

    for specifying things like choice of :processor (processor defaults to :image)

Options Hash (opts):

  • :processor (Symbol) — default: :image

    Processor to use

  • :source_file_service (Class) — default: Hydra::Derivatives::RetrieveSourceFileService

    service to use when persisting generated derivatives. The default for this can be set in your config file.

  • :output_file_service (Class) — default: Hydra::Derivatives::PersistIndirectlyContainedOutputFile

    service to use when retrieving the source. The default for this can be set in your config file.



103
104
105
# File 'lib/hydra/derivatives.rb', line 103

def transform_file(file_name, transform_directives, opts={})
  initialize_processor(file_name, transform_directives, opts).process
end