Class: Kithe::MediainfoAnalyzer
- Inherits:
-
Object
- Object
- Kithe::MediainfoAnalyzer
- Defined in:
- app/models/kithe/mediainfo_analyzer.rb
Overview
Determines MIME/Internet Content Type by calling out to ‘mediainfo` CLI, which must be installed on machine.
Catches some A/v types that for some fles ordinary “magic byte” detection does not.
When we had some files not being properly determined to be audio/mpeg, we looked into what Harvard fits used, saw mediainfo was one of the tools, so decided we would use that as a fallback. Since it will be much slower than the magic-byte-based detection.
Not sure how reliable ‘mediainfo` is for non-media files, plus it we use it as a fallback.
The API is similar to the internal Shrine::DetermineMimeType::MimeTypeAnalyzer, it is based on that.
MediainfoAnalyzer.new.call(io)
#=> "audio/mpeg"
#=> nil if mediainfo has no idea
Instance Method Summary collapse
-
#call(io, _options = {}) ⇒ Object
returns mime-type as determined by shell out to mediainfo command.
Instance Method Details
#call(io, _options = {}) ⇒ Object
returns mime-type as determined by shell out to mediainfo command
io argument will have ‘rewind` called before returning.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/kithe/mediainfo_analyzer.rb', line 31 def call(io, ={}) # To use 'mediainfo' we need a local file, which if the file is currently remote means we # will have to download a local copy into a tempfile, this could take a while for a big file. Shrine.with_file(io) do |tempfile| out, err = tty_command.run("#{mediainfo_command} --Inform=\"General;%InternetMediaType%\"", tempfile.path) mime_type = out.chomp mime_type = nil if mime_type.blank? return mime_type end end |