Sha256: 379be93328e336f1f65c2c1bf331ce2c9cd05787fbf99d06f0868fc46cdb2320
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
require 'open3' module Hydra module Derivatives module ExtractMetadata include Open3 def extract_metadata out = nil to_tempfile do |f| out = run_fits!(f.path) end out end def to_tempfile &block return unless has_content? type = MIME::Types[mimeType].first logger.warn "Unable to find a registered mime type for #{mimeType.inspect} on #{pid}" unless type extension = type ? ".#{type.extensions.first}" : '' f = Tempfile.new(["#{pid}-#{dsVersionID}", extension]) f.binmode if content.respond_to? :read f.write(content.read) else f.write(content) end f.close content.rewind if content.respond_to? :rewind yield(f) f.unlink end private def run_fits!(file_path) command = "#{fits_path} -i \"#{file_path}\"" stdin, stdout, stderr, wait_thr = popen3(command) stdin.close out = stdout.read stdout.close err = stderr.read stderr.close exit_status = wait_thr.value raise "Unable to execute command \"#{command}\"\n#{err}" unless exit_status.success? out end def fits_path Hydra::Derivatives.fits_path end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hydra-derivatives-0.0.5 | lib/hydra/derivatives/extract_metadata.rb |
hydra-derivatives-0.0.4 | lib/hydra/derivatives/extract_metadata.rb |