Apple iTunes StoreのデータをPythonから利用する

前回のエントリーでsimplejsonをインストールしてPythonからJSONを使いたいな〜〜〜と思ったのは、

JSON形式のデータフォーマットで提供されているApple iTunes Store内のアーティストデータを、Pythonで利用したいな〜〜〜と思ったからなのですが、

iTunes Store内のアーティストデータは、iTunes StoreのWeb APIを使って、例えば、以下のような感じで利用することが出来ます。

【例】iTunes Storeからamazarashiのデータを引っ張って来る。(やっつけソースですが。。。)

from urllib2 import *
import simplejson as json  (← Python2.6 以降を使える場合はここは「import json」 )
from StringIO import StringIO
conn = urlopen('http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch?term=amazarashi&country=JP&lang=ja_jp&media=music')
j=json.load(StringIO(conn.read()))
for i in range( int( j['resultCount'] ) ):
    print 'No.', i + 1
    for key in sorted(j['results'][i].keys()):
        data = j['results'][i][key]
        if key == 'artworkUrl100':
            print '<img src="' + data + '">'
        print key, " ==> ", data

【結果】

No. 1
artistId ==> 342419284
artistName ==> amazarashi
artistViewUrl ==> https://itunes.apple.com/jp/artist/amazarashi/id342419284?uo=4

artworkUrl100 ==> http://a2.mzstatic.com/us/r1000/007/Music/63/42/0e/mzi.qgolaffm.100x100-75.jpg
artworkUrl30 ==> http://a2.mzstatic.com/us/r1000/007/Music/63/42/0e/mzi.qgolaffm.30x30-50.jpg
artworkUrl60 ==> http://a4.mzstatic.com/us/r1000/007/Music/63/42/0e/mzi.qgolaffm.60x60-50.jpg
collectionCensoredName ==> amazarashi 0.6
collectionExplicitness ==> notExplicit
collectionId ==> 353486993
collectionName ==> amazarashi 0.6
collectionPrice ==> 1050.0
collectionViewUrl ==> https://itunes.apple.com/jp/album/guang-zai-kao/id353486993?i=353487016&uo=4
country ==> JPN
currency ==> JPY
discCount ==> 1
discNumber ==> 1
kind ==> song
previewUrl ==> http://a1848.phobos.apple.com/us/r1000/104/Music/v4/f3/e1/b0/f3e1b05d-6afd-0452-1fa2-80838846171d/mzaf_6970950198899833653.aac.m4a
primaryGenreName ==> Rock
releaseDate ==> 2010-02-10T08:00:00Z
trackCensoredName ==> 光、再考
trackCount ==> 7
trackExplicitness ==> notExplicit
trackId ==> 353487016
trackName ==> 光、再考
trackNumber ==> 1
trackPrice ==> 150.0
trackTimeMillis ==> 338668
trackViewUrl ==> https://itunes.apple.com/jp/album/guang-zai-kao/id353486993?i=353487016&uo=4
wrapperType ==> track
No. 2
artistId ==> 342419284
artistName ==> amazarashi
artistViewUrl ==> https://itunes.apple.com/jp/artist/amazarashi/id342419284?uo=4

artworkUrl100 ==> http://a2.mzstatic.com/us/r30/Music2/v4/a4/94/a0/a494a09e-dbe4-299e-9525-e9f6c67a82bd/jacket_AIXX00396B01A_550.100x100-75.jpg
artworkUrl30 ==> http://a1.mzstatic.com/us/r30/Music2/v4/a4/94/a0/a494a09e-dbe4-299e-9525-e9f6c67a82bd/jacket_AIXX00396B01A_550.30x30-50.jpg
artworkUrl60 ==> http://a3.mzstatic.com/us/r30/Music2/v4/a4/94/a0/a494a09e-dbe4-299e-9525-e9f6c67a82bd/jacket_AIXX00396B01A_550.60x60-50.jpg
collectionCensoredName ==> ジュブナイル - Single
collectionExplicitness ==> notExplicit
collectionId ==> 620316449
collectionName ==> ジュブナイル - Single
collectionPrice ==> 250.0
collectionViewUrl ==> https://itunes.apple.com/jp/album/jubunairu/id620316449?i=620316493&uo=4
country ==> JPN
currency ==> JPY
discCount ==> 1
discNumber ==> 1
kind ==> song
previewUrl ==> http://a970.phobos.apple.com/us/r30/Music/v4/90/2d/af/902daf21-50e9-98f7-8f78-d110393007d4/mzaf_8513056837175210941.aac.m4a
primaryGenreName ==> Rock
releaseDate ==> 2013-03-27T07:00:00Z
trackCensoredName ==> ジュブナイル
trackCount ==> 1
trackExplicitness ==> notExplicit
trackId ==> 620316493
trackName ==> ジュブナイル
trackNumber ==> 1
trackPrice ==> 250.0
trackTimeMillis ==> 269520
trackViewUrl ==> https://itunes.apple.com/jp/album/jubunairu/id620316449?i=620316493&uo=4
wrapperType ==> track
No. 3
artistId ==> 342419284
artistName ==> amazarashi
artistViewUrl ==> https://itunes.apple.com/jp/artist/amazarashi/id342419284?uo=4

artworkUrl100 ==> http://a2.mzstatic.com/us/r1000/007/Music/63/42/0e/mzi.qgolaffm.100x100-75.jpg
artworkUrl30 ==> http://a2.mzstatic.com/us/r1000/007/Music/63/42/0e/mzi.qgolaffm.30x30-50.jpg
artworkUrl60 ==> http://a4.mzstatic.com/us/r1000/007/Music/63/42/0e/mzi.qgolaffm.60x60-50.jpg
collectionCensoredName ==> amazarashi 0.6
collectionExplicitness ==> notExplicit
collectionId ==> 353486993
collectionName ==> amazarashi 0.6
collectionPrice ==> 1050.0
collectionViewUrl ==> https://itunes.apple.com/jp/album/shi-qi-hewaseni-shengmareta/id353486993?i=353487014&uo=4
country ==> JPN
currency ==> JPY
discCount ==> 1
discNumber ==> 1
kind ==> song
previewUrl ==> http://a436.phobos.apple.com/us/r1000/081/Music/v4/ba/c3/b2/bac3b220-7a83-6ca3-133a-19d6717915ec/mzaf_8011314659670408930.aac.m4a
primaryGenreName ==> Rock
releaseDate ==> 2010-02-10T08:00:00Z
trackCensoredName ==> 辻褄合わせに生まれた僕等
trackCount ==> 7
trackExplicitness ==> notExplicit
trackId ==> 353487014
trackName ==> 辻褄合わせに生まれた僕等
trackNumber ==> 2
trackPrice ==> 150.0
trackTimeMillis ==> 339485
trackViewUrl ==> https://itunes.apple.com/jp/album/shi-qi-hewaseni-shengmareta/id353486993?i=353487014&uo=4
wrapperType ==> track


No. 32
artistId ==> 342419284
artistName ==> amazarashi
artistViewUrl ==> https://itunes.apple.com/jp/artist/amazarashi/id342419284?uo=4

artworkUrl100 ==> http://a4.mzstatic.com/us/r30/Music/v4/63/50/4e/63504e4b-59cc-da95-ef8b-34fffd50e893/jacket_AICL02128B01A_600over.100x100-75.jpg
artworkUrl30 ==> http://a5.mzstatic.com/us/r30/Music/v4/63/50/4e/63504e4b-59cc-da95-ef8b-34fffd50e893/jacket_AICL02128B01A_600over.30x30-50.jpg
artworkUrl60 ==> http://a4.mzstatic.com/us/r30/Music/v4/63/50/4e/63504e4b-59cc-da95-ef8b-34fffd50e893/jacket_AICL02128B01A_600over.60x60-50.jpg
collectionCensoredName ==> 爆弾の作り方
collectionExplicitness ==> notExplicit
collectionId ==> 570047897
collectionName ==> 爆弾の作り方
collectionPrice ==> 1500.0
collectionViewUrl ==> https://itunes.apple.com/jp/album/bao-danno-zuori-fang/id570047897?i=570048084&uo=4
country ==> JPN
currency ==> JPY
discCount ==> 1
discNumber ==> 1
kind ==> song
previewUrl ==> http://a275.phobos.apple.com/us/r30/Music/v4/d1/b0/25/d1b0256f-d9b3-c322-3732-d1cd80a1d04a/mzaf_9158864821615303970.aac.m4a
primaryGenreName ==> Pop
releaseDate ==> 2010-06-09T07:00:00Z
trackCensoredName ==> 爆弾の作り方
trackCount ==> 6
trackExplicitness ==> notExplicit
trackId ==> 570048084
trackName ==> 爆弾の作り方
trackNumber ==> 3
trackPrice ==> 250.0
trackTimeMillis ==> 302387
trackViewUrl ==> https://itunes.apple.com/jp/album/bao-danno-zuori-fang/id570047897?i=570048084&uo=4
wrapperType ==> track

(以下略)