Gracenote is a metadata service for music information. Music data can be obtained from the artist name, album name, and song name. In addition to music information, you can also get mood and tempo information. I have summarized the results of examining the library for Ruby / Python to use the Web API from Gracenote.
From here (https://developer.gracenote.com/?language=en), you can enroll in the developer program. If it is Japanese, a language error may appear on the management screen after Facebook authentication is completed, so English is recommended. When you enter the management screen, select the MyApps button, select "Add a new app", and then "Create App" to issue a client ID.
My Apps
Add App
App Details
WebAPI uses "Client ID for Web API, Rhythm API and eyeQ" and "Client Tag".
Ruby gracenote https://github.com/nobelium/gracenote
Move for the time being
$ gem install gracenote
$ vi sample.rb
sample.rb
require 'rubygems'
require 'gracenote'
obj = Gracenote.new(
clientID: '',
clientTag: ''
)
obj.registerUser
artist_name = 'Perfume'
album_title = 'GAME'
track_title = 'chocolate disco'
match_mode = '0'
p obj.findTrack(artist_name, album_title, track_title, match_mode)
$ ruby ./sample.rb
--I can't search by gnid --NET :: HTTP is used, so it's synchronous communication.
Well, I wonder if it's just a text search for albums, artists, and song titles
under_fire https://github.com/jasonthompson/under_fire/
It doesn't work as it is, so it can't be used I rewrote it to work, but it's better to make it from scratch.
Since clientTag is also included in CLIENT_ID, it may not be necessary depending on the creation of the library.
$ gem install under_fire
$ vi sample.rb
sample.rb
require 'rubygems'
require 'under_fire'
ENV["GRACENOTE_CLIENT_ID"] = 'your client id'
module UnderFire
class BaseQuery
def build_base_query(&block)
builder = Builder::XmlMarkup.new
builder.QUERIES {
builder.AUTH {
builder.CLIENT ENV["GRACENOTE_CLIENT_ID"]
builder.USER ENV["GRACENOTE_USER"]
}
yield builder
}
end
end
end
module UnderFire
class APIRequest
def self.post(query, api_url)
uri = URI(api_url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
req.body = query
req['Content-Type'] = 'application/xml'
res = http.request(req)
res
end
end
end
client = UnderFire::Client.new
response = client.register(ENV["GRACENOTE_CLIENT_ID"])
ENV["GRACENOTE_USER"] = response.response[:responses][:response][:user]
p client.find_album(:track_title => 'chocolate disco')
$ ruby ./sample.rb
--I get an SSL communication error --Language Preference is fixed --Authentication cannot be performed without using the USERID obtained by register, but since it has not been rewritten, an authentication error occurs.
--The Track API is not implemented, so you can't get the tempo or mood. --NET :: HTTP is used, so it's synchronous communication.
--Compared to gracenote gem, the interface can be searched from Ruby-like gn_id
Python
pygn
To use it, just copy pygn.py and put it in your working directory. As it is, it can not be read even if it is installed with pip It is easy to use because all the functions are implemented. Since the source code is one file, it is quick to read the code.
$ wget https://raw.githubusercontent.com/cweichen/pygn/master/pygn.py
$ vi sample.py
sample.py
import pygn
clientID = '' # Enter your Client ID here
userID = pygn.register(clientID)
metadata = pygn.search(clientID=clientID, userID=userID, artist='Perfume')
print metadata
$ python ./sample.py
There is no official Ruby / Python client library, so you have to use a third party. The one for Python works reasonably well, so if you want to use it quickly, I recommend pygn. Performance is not good when used properly, so I would like to change the communication surroundings to an asynchronous library and reimplement it in Ruby, or write it in Go or Elixer for study.
Recommended Posts