LoginSignup
9
6

More than 5 years have passed since last update.

echonest の python client で API をたたいてみた

Last updated at Posted at 2016-03-01

echonest とは

The Echo Nest は、音楽情報のデータベースを扱う企業で、2014 年に Spotify に買収されたようです。
音楽情報の API を公開しています。
http://the.echonest.com/

echonest の公開しているライブラリ

試した環境

Centos 7.2
Python 2.7
今回は Pyechonest を使ってみました

Pyechonest のインストール

easy_install -U pyechonest

API key の取得

http://developer.echonest.com/
こちらからフリーのアカウントを作成します。
メールにてアカウント有効化の確認が届きます。

Your Profile のページに Your API Key: が表示されます
https://developer.echonest.com/account/profile

Examples をベースにして python ファイルを作成します

Bikini Kill ではなく Duke Ellington に似たアーティストを表示させます。

vi echotest.py

echotest1.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

from pyechonest import config
config.ECHO_NEST_API_KEY="YOURAPIKEY"

from pyechonest import artist
de = artist.Artist('duke ellington')
print "Artists similar to: %s:" % (de.name,)
for similar_artist in de.similar: print "\t%s" % (similar_artist.name,)

結果

Artists similar to: Duke Ellington:
    Count Basie
    The Duke Ellington Band
    Earl Hines
    Woody Herman
    Count Basie Orchestra
    Stan Kenton
    Benny Carter
    Lionel Hampton
    Benny Goodman
    Teddy Wilson
    Johnny Hodges
    Fletcher Henderson
    Buddy Rich
    Duke Ellington Orchestra
    Harry James

年代的な相関を重視しているような結果に見えます。

アーティスト ID を表示します

echotest2.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

from pyechonest import config
config.ECHO_NEST_API_KEY="YOURAPIKEY"

from pyechonest import artist
a = artist.Artist('duke ellington')
print a.id

結果

ARMI36C1187B99A462

Duke Ellington の アーティストの出身地および Perdido という曲のテンポ、曲の長さを表示します

echotest3.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

from pyechonest import config
config.ECHO_NEST_API_KEY="YOURAPIKEY"

from pyechonest import song
de_results = song.search(artist='duke ellington', title='perdido')
perdido = de_results[0]
print perdido.artist_location
print 'tempo:',perdido.audio_summary['tempo'],'duration:',perdido.audio_summary['duration']

結果

{u'latitude': 47.3917, u'location': u'Washington D.C. ', u'longitude': -121.5708}
tempo: 129.606 duration: 188.4

さいごに

もっと音楽 API の記事が増えてほしいなと思って書きました。
http://qiita.com/hideyuki/items/8b5c6b02d0784aa25fd2

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6