Class: EivuFingerprinterAcoustid::Engine
- Inherits:
-
Object
- Object
- EivuFingerprinterAcoustid::Engine
- Defined in:
- lib/eivu_fingerprinter_acoustid/engine.rb
Constant Summary collapse
- SERVICE_LOOKUP_URL =
"https://api.acoustid.org/v2/lookup"- SETTINGS =
"recordings+releasegroups+compress"
Instance Attribute Summary collapse
-
#calc_output ⇒ Object
readonly
Returns the value of attribute calc_output.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #cleansed_fingerprint_url ⇒ Object
- #fingerprint_url ⇒ Object
- #generate(path_to_file) ⇒ Object
-
#initialize ⇒ Engine
constructor
A new instance of Engine.
- #submit ⇒ Object
Constructor Details
#initialize ⇒ Engine
Returns a new instance of Engine.
21 22 23 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 21 def initialize @client_id = ENV.fetch("ACOUSTID_CLIENT_ID", nil) end |
Instance Attribute Details
#calc_output ⇒ Object (readonly)
Returns the value of attribute calc_output.
13 14 15 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 13 def calc_output @calc_output end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
13 14 15 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 13 def duration @duration end |
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
13 14 15 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 13 def fingerprint @fingerprint end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
13 14 15 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 13 def raw_response @raw_response end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
13 14 15 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 13 def response @response end |
Class Method Details
.identify(path_to_file = nil) ⇒ Object
15 16 17 18 19 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 15 def self.identify(path_to_file = nil) instance = new instance.generate(path_to_file) instance.submit end |
Instance Method Details
#cleansed_fingerprint_url ⇒ Object
48 49 50 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 48 def cleansed_fingerprint_url fingerprint_url.gsub(@client_id, "<ACOUSTID_CLIENT_ID>") end |
#fingerprint_url ⇒ Object
44 45 46 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 44 def fingerprint_url "#{SERVICE_LOOKUP_URL}?client=#{@client_id}&duration=#{@duration}&fingerprint=#{@fingerprint}&meta=#{SETTINGS}" end |
#generate(path_to_file) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 25 def generate(path_to_file) # call fingerprint calculator @calc_output = execute_binary(path_to_file) # output is in the format of: # DURATION=267 # FINGERPRINT=AQADtHKTZFJG7LSwHxeJuGmhj4i6Bj info = @calc_output.split("\n").each_with_object({}) do |line, hash| key, value = line.strip.split("=") hash[key.downcase.to_sym] = value end @fingerprint = info[:fingerprint] @duration = info[:duration]&.to_i end |
#submit ⇒ Object
39 40 41 42 |
# File 'lib/eivu_fingerprinter_acoustid/engine.rb', line 39 def submit @raw_response = RestClient.get(fingerprint_url) @response = Oj.load(@raw_response)&.deep_symbolize_keys end |