8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
|
# File 'lib/earworm/fingerprint.rb', line 8
def to_hash
return @hash if @hash
info = nil
@hash = {
'art' => 'unknown',
'ttl' => 'unknown',
'alb' => 'unknown',
'tnm' => 0,
'gnr' => 'unknown',
'yrr' => 0,
'brt' => 0,
'fmt' => 'wav',
}
if @thing.is_a?(IO)
info = wav_info_for(@thing)
else
tmpfile = case @thing
when /mp3$/
@hash['fmt'] = 'mp3'
begin
require 'id3lib'
@hash = @hash.merge(id3_info_for(@thing))
rescue LoadError
end
decode_mp3(@thing)
when /ogg$/
@hash['fmt'] = 'ogg'
decode_ogg(@thing)
else
@thing
end
File.open(tmpfile, 'rb') { |f|
info = wav_info_for(f)
}
end
@hash['fpt'] = info[:fpt]
@hash['dur'] = info[:milliseconds]
@hash
end
|