Class: Audd::RecognitionResult

Inherits:
Model
  • Object
show all
Defined in:
lib/audd/models/recognition_result.rb

Overview

A single recognition result. Which fields are populated depends on which catalog matched:

  • public-DB match — artist, title, album, release_date, label and song_link are populated and audio_id is absent;
  • custom-DB match (your own fingerprint catalog) — only timecode and audio_id are populated.

Use #public_match? / #custom_match? rather than testing artist for nil.

Constant Summary collapse

THUMBNAIL_HOST =

Only lis.tn-hosted song links serve cover art from ?thumb.

"lis.tn"

Instance Attribute Summary

Attributes inherited from Model

#raw

Instance Method Summary collapse

Methods inherited from Model

#==, #[], field, fields, from_json, #hash, #initialize, #inspect, #to_h

Constructor Details

This class inherits a constructor from Audd::Model

Instance Method Details

#custom_match?Boolean

Matched against your own fingerprint catalog rather than the public DB.

Returns:

  • (Boolean)


40
41
42
# File 'lib/audd/models/recognition_result.rb', line 40

def custom_match?
  !audio_id.nil?
end

#public_match?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/audd/models/recognition_result.rb', line 44

def public_match?
  audio_id.nil?
end

#thumbnail_urlObject

Cover art for the match, or nil when there's no song_link to build it from — appending ?thumb only means anything on lis.tn.



50
51
52
53
54
55
56
57
# File 'lib/audd/models/recognition_result.rb', line 50

def thumbnail_url
  return nil if song_link.nil?
  return nil unless URI.parse(song_link).host == THUMBNAIL_HOST

  "#{song_link}?thumb"
rescue URI::InvalidURIError
  nil
end