Class: Earworm::Fingerprint
- Inherits:
-
Object
- Object
- Earworm::Fingerprint
- Defined in:
- lib/earworm/fingerprint.rb
Instance Method Summary collapse
-
#initialize(thing) ⇒ Fingerprint
constructor
A new instance of Fingerprint.
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(thing) ⇒ Fingerprint
Returns a new instance of Fingerprint.
3 4 5 6 |
# File 'lib/earworm/fingerprint.rb', line 3 def initialize(thing) @thing = thing @hash = nil end |
Instance Method Details
#to_hash ⇒ Object
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 # Assume its a wav file @thing end File.open(tmpfile, 'rb') { |f| info = wav_info_for(f) } end @hash['fpt'] = info[:fpt] @hash['dur'] = info[:milliseconds] @hash end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/earworm/fingerprint.rb', line 48 def to_s to_hash['fpt'] end |