Class: Shrine::Plugins::KitheDetermineMimeType
- Inherits:
-
Object
- Object
- Shrine::Plugins::KitheDetermineMimeType
- Defined in:
- lib/shrine/plugins/kithe_determine_mime_type.rb
Overview
Custom kithe logic for determining mime type, using the shrine mime_type plugin.
We start out using the ‘marcel` analyzer. Marcel analyzer is pure-ruby and fast. It’s from Basecamp and is what ActiveStorage uses. It is very similar to :mimemagic (and uses mimemagic under the hood), but mimemagic seems not to be maintained with up to date magic db? github.com/minad/mimemagic/pull/66
But marcel is not able to catch some of our MP3s as audio/mpeg. The ‘mediainfo` CLI is, and is one of the tools Harvard FITS uses. If marcel came up blank, AND we are configured to use mediainfo CLI (which by default we will be if it’s available), we will try shelling out to mediainfo command line.
github.com/MediaArea/MediaInfo
Ensure that if mime-type can’t be otherwise determined, it is assigned “application/octet-stream”, basically the type for generic binary.
Constant Summary collapse
- RPELACE_CONTENT_TYPES =
marcel version 1.0 says audio/x-flac, whereas previous versions said audio/flac, which we prefer. Let’s fix it.
{ "audio/x-flac" => "audio/flac" }
Class Method Summary collapse
Class Method Details
.load_dependencies(uploader) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/shrine/plugins/kithe_determine_mime_type.rb', line 28 def self.load_dependencies(uploader, *) uploader.plugin :determine_mime_type, analyzer: -> (io, analyzers) do mime_type = analyzers[:marcel].call(io) if Kithe.use_mediainfo && mime_type == "application/octet-stream" || mime_type.blank? mime_type = Kithe::MediainfoAnalyzer.new.call(io) end mime_type = "application/octet-stream" if mime_type.blank? # Are there any we prefer an alternate spelling of? mime_type = RPELACE_CONTENT_TYPES.fetch(mime_type, mime_type) mime_type end end |