[RUBY] I checked the library for using the Gracenote API

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.

Get client ID

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

My_Apps___Gracenote.png

Add App

Add_App___Gracenote.png

App Details

mhd_demo___Gracenote.png

WebAPI uses "Client ID for Web API, Rhythm API and eyeQ" and "Client Tag".

Ruby gracenote https://github.com/nobelium/gracenote

Impressions

Move for the time being

Sample code

$ 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)

Run

$ ruby ./sample.rb

Where it's not cool

--I can't search by gnid --NET :: HTTP is used, so it's synchronous communication.

Conclusion

Well, I wonder if it's just a text search for albums, artists, and song titles

under_fire https://github.com/jasonthompson/under_fire/

Impressions

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.

Sample code

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')

Run

$ ruby ./sample.rb

Where it's not cool

--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.

Other

--The Track API is not implemented, so you can't get the tempo or mood. --NET :: HTTP is used, so it's synchronous communication.

Good point

--Compared to gracenote gem, the interface can be searched from Ruby-like gn_id

Python

pygn

Impressions

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.

Sample 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

Run

$ python ./sample.py

Summary

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

I checked the library for using the Gracenote API
I tried using the checkio API
[For beginners] I tried using the Tensorflow Object Detection API
I tried using the BigQuery Storage API
I tried using scrapy for the first time
vprof --I tried using the profiler for Python
I tried using the Google Cloud Vision API
I tried using the functional programming library toolz
I tried using the API of the salmon data project
Using the National Diet Library Search API in Python
Try using the Twitter API
I touched the Qiita API
Try using the Twitter API
I tried the changefinder library!
Try using the PeeringDB 2.0 API
I tried using the Python library from Ruby with PyCall
I tried touching the multi-vendor router control API library NAPALM
Miscellaneous notes that I tried using python for the matter
[Python] I tried collecting data using the API of wikipedia
I tried the Google Cloud Vision API for the first time
For the time being, try using the docomo chat dialogue API
I made an original program guide using the NHK program guide API.
[For those who want to use TPU] I tried using the Tensorflow Object Detection API 2
I tried the Naro novel API 2
Tokenize using the Hugging Face library
I tried the Naruro novel API
I checked the gift tax amount
I tried using the python module Kwant for quantum transport calculation
I created a Python library to call the LINE WORKS API
I tried using the COTOHA API (there is code on GitHub)
Continuation ・ I tried touching the multi-vendor router control API library NAPALM
I made a Python wrapper library for docomo image recognition API.
I made my own research tool using the legal API [Smart Roppo]
Try using the Wunderlist API in Python
I tried logistic regression analysis for the first time using Titanic data
I tried using Twitter api and Line api
I tried tensorflow for the first time
I checked the options of copyMakeBorder of OpenCV
Try using the Kraken API in Python
I tried using YOUTUBE Data API V3
I stumbled on the Hatena Keyword API
Tweet using the Twitter API in Python
Try sending an email with the Gmail API Client Library for Java
I tried using UnityCloudBuild API from Python
I tried to summarize various sentences using the automatic summarization API "summpy"
I tried using the trained model VGG16 of the deep learning library Keras
3 small stories I checked while using Chalice
Create an application using the Spotify API
I tried to touch the COTOHA API
I wrote the code for Gibbs sampling
[Text classification] I tried using the Attention mechanism for Convolutional Neural Networks.
Play with puns using the COTOHA API
For the time being using FastAPI, I want to display how to use API like that on swagger
Record custom events using the Shotgun API
I made a library for actuarial science
I made a LINE BOT that returns a terrorist image using the Flickr API
I tried Hello World with 64bit OS + C language without using the library
I tried using the Python library "pykakasi" that can convert kanji to romaji.
When I tried using Microsoft's Computer Vision API, I recognized the Galapagos sign "Stop"
Touch the sample v20-python-samples of the OANDA v20 REST API wrapper library for Python
I tried using AWS Rekognition's Detect Labels API