@@ -67,49 +67,39 @@ def supported_mime_types
6767 end
6868
6969 def create_pdf_derivatives ( filename )
70- Hydra ::Derivatives ::PdfDerivatives . create ( filename ,
71- outputs : [ {
72- label : :thumbnail ,
73- format : 'jpg' ,
74- size : '338x493' ,
75- url : derivative_url ( 'thumbnail' ) ,
76- layer : 0
77- } ] )
78- extract_full_text ( filename , derivative_url ( 'extracted_text' ) )
70+ create_derivatives_for ( :pdf , filename , Hydra ::Derivatives ::PdfDerivatives )
7971 end
8072
8173 def create_office_document_derivatives ( filename )
82- Hydra ::Derivatives ::DocumentDerivatives . create ( filename ,
83- outputs : [ {
84- label : :thumbnail , format : 'jpg' ,
85- size : '200x150>' ,
86- url : derivative_url ( 'thumbnail' ) ,
87- layer : 0
88- } ] )
89- extract_full_text ( filename , derivative_url ( 'extracted_text' ) )
74+ create_derivatives_for ( :office , filename , Hydra ::Derivatives ::DocumentDerivatives )
9075 end
9176
9277 def create_audio_derivatives ( filename )
93- Hydra ::Derivatives ::AudioDerivatives . create ( filename ,
94- outputs : [ { label : 'mp3' , format : 'mp3' , url : derivative_url ( 'mp3' ) , mime_type : 'audio/mpeg' , container : 'service_file' } ,
95- { label : 'ogg' , format : 'ogg' , url : derivative_url ( 'ogg' ) , mime_type : 'audio/ogg' , container : 'service_file' } ] )
78+ create_derivatives_for ( :audio , filename , Hydra ::Derivatives ::AudioDerivatives )
9679 end
9780
9881 def create_video_derivatives ( filename )
99- Hydra ::Derivatives ::VideoDerivatives . create ( filename ,
100- outputs : [ { label : :thumbnail , format : 'jpg' , url : derivative_url ( 'thumbnail' ) , mime_type : 'image/jpeg' } ,
101- { label : 'webm' , format : 'webm' , url : derivative_url ( 'webm' ) , mime_type : 'video/webm' , container : 'service_file' } ,
102- { label : 'mp4' , format : 'mp4' , url : derivative_url ( 'mp4' ) , mime_type : 'video/mp4' , container : 'service_file' } ] )
82+ create_derivatives_for ( :video , filename , Hydra ::Derivatives ::VideoDerivatives )
10383 end
10484
10585 def create_image_derivatives ( filename )
106- # We're asking for layer 0, becauase otherwise pyramidal tiffs flatten all the layers together into the thumbnail
107- Hydra ::Derivatives ::ImageDerivatives . create ( filename ,
108- outputs : [ { label : :thumbnail ,
109- format : 'jpg' ,
110- size : '200x150>' ,
111- url : derivative_url ( 'thumbnail' ) ,
112- layer : 0 } ] )
86+ create_derivatives_for ( :image , filename , Hydra ::Derivatives ::ImageDerivatives )
87+ end
88+
89+ # Routes +extracted_text+ outputs to full text extraction; the rest to +processor+.
90+ def create_derivatives_for ( type , filename , processor )
91+ text_outputs , processor_outputs = derivative_outputs ( type ) . partition { |output | output [ :container ] == 'extracted_text' }
92+ processor . create ( filename , outputs : processor_outputs ) if processor_outputs . any?
93+ extract_full_text ( filename , text_outputs ) if text_outputs . any?
94+ end
95+
96+ # Resolves configured specs for +type+: callable values are invoked with the
97+ # file set, and +:url+ destination names become real derivative URLs.
98+ def derivative_outputs ( type )
99+ Hyrax . config . derivative_options . fetch ( type ) . map do |output |
100+ resolved = output . transform_values { |value | value . respond_to? ( :call ) ? value . call ( file_set ) : value }
101+ resolved . merge ( url : derivative_url ( resolved [ :url ] ) )
102+ end
113103 end
114104
115105 def derivative_path_factory
@@ -119,12 +109,11 @@ def derivative_path_factory
119109 # Calls the Hydra::Derivates::FulltextExtraction unless the extract_full_text
120110 # configuration option is set to false
121111 # @param [String] filename of the object to be used for full text extraction
122- # @param [String] uri to the file set (deligated to file_set)
123- def extract_full_text ( filename , uri )
112+ # @param [Array<Hash>] outputs the resolved extracted_text output specs
113+ def extract_full_text ( filename , outputs )
124114 return unless Hyrax . config . extract_full_text?
125115
126- Hydra ::Derivatives ::FullTextExtract . create ( filename ,
127- outputs : [ { url : uri , container : "extracted_text" } ] )
116+ Hydra ::Derivatives ::FullTextExtract . create ( filename , outputs : outputs )
128117 end
129118 end
130119end
0 commit comments