22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/libis/format/fido.rb', line 22
def run(file, xtra_formats = nil)
fido_results = []
fmt_list = formats.dup
case xtra_formats
when Array
fmt_list += xtra_formats
when String
fmt_list << xtra_formats
else
end
args = []
args << '-loadformats' << "#{fmt_list.join(',')}" unless fmt_list.empty?
args << "#{file.escape_for_string}"
fido = ::Libis::Tools::Command.run(Libis::Format::Config[:fido_path], *args)
warn "Fido errors: #{fido[:err].join("\n")}" unless fido[:err].empty?
keys = [:status, :time, :puid, :format_name, :signature_name, :filesize, :filename, :mimetype, :matchtype]
fido_output = CSV.parse(fido[:out].join("\n")).map { |a| Hash[keys.zip(a)] }
fido_output.each do |x|
if x[:status] == 'OK'
x[:mimetype] = get_mimetype(x[:puid]) if x[:mimetype] == 'None'
next if BAD_MIMETYPES.include? x[:mimetype]
x[:score] = 5
case x[:matchtype]
when 'signature'
x[:score] += 5
when 'container'
typeinfo = ::Libis::Format::TypeDatabase.puid_typeinfo(x[:puid])
ext = File.extname(file)
x[:score] += 2 if typeinfo and typeinfo[:EXTENSIONS].include?(ext)
else
end
fido_results << x
end
end
fido_results = fido_results.inject({}) do |result, value|
result[value[:score]] ||= []
result[value[:score]] << value
result
end
max_score = fido_results.keys.max
return {} unless max_score and max_score >= 5 && fido_results[max_score].size == 1
fido_results[max_score].first
end
|