I will post it to Qiita, thinking that there are people who handle such APIs. It's a technical blog, so if it's related, you can write anything. There is nothing else to mention here for today's dinner.
ITunes is something you probably don't know about iPods and iPhones, but it's the Gracenote API that's used to insert CDs and tag songs. All kinds of songs from ancient times to east and west are registered, and especially in Japan, doujin music and drama CDs of eroge reservation benefits are recognized. Who is registered? Really ... (This country is already ...)
It's such an excellent API, but iTunes has a GNSDK that can do anything (C language). The Web API is a simplified version, but it returns quite detailed content. If you throw XML, it will return it in XML. (I personally prefer JSON, but) I have a wrapper, so it's pretty good.
I'm Pythonista so I only use pygn. (I like Python the most, but I'm also interested in C # and Node.js, so I may post it if I have time ...) Please register with Gracenote in advance to obtain the cliant ID and user ID.
I will write in a super sink. It's not the main subject of today.
test.py
import pygn, json
clientID = 'XXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
userID = 'XXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
def beautiful(gn_obj):
data = json.dumps(gn_obj, sort_keys=True, indent=4, ensure_ascii=False)
return data
res = beautiful(pygn.search(clientID=clientID, userID=userID, album='Oh! Rival', artist='Porno graffiti'))
print(res)
Save it as ./test.py> res.json
.
I just made pygn correspond to \ <LANG > ja \ </ LANG >. This is a patch file.
pygn.patch
--- /home/hoge/Download/pygn-master/pygn.py 2015-05-15 17:06:08.436636117 +0900
+++ /usr/local/lib/python3.4/dist-packages/pygn.py 2015-05-15 04:04:38.551710764 +0900
@@ -7,6 +7,8 @@
You will need a Gracenote Client ID to use this module. Please contact
[email protected] to get one.
+
+<LANG>Optional version
"""
from __future__ import print_function
@@ -100,7 +102,8 @@
# Added by Fabian in order to cover the Rhythm API
# Returns a list of gnmetadata dictionaries
-def createRadio(clientID='', userID='', artist='', track='', mood='', era='', genre='', popularity ='', similarity = '', count='10'):
+def createRadio(clientID='', userID='', lang='', artist='', track='', mood='', era='', genre='',
+ popularity ='', similarity = '', count='10'):
"""
Queries a Radio playlist
"""
@@ -117,6 +120,7 @@
# Build the user header
query.addAuth(clientID, userID)
+ query.addLang(lang)
query.addQuery('RADIO_CREATE')
@@ -228,7 +232,7 @@
#***********************************************************************************************************************
-def search(clientID='', userID='', artist='', album='', track='', toc=''):
+def search(clientID='', userID='',lang='', artist='', album='', track='', toc=''):
"""
Queries the Gracenote service for a track, album, artist, or TOC
@@ -247,6 +251,7 @@
query = _gnquery()
query.addAuth(clientID, userID)
+ query.addLang(lang)
if (toc != ''):
query.addQuery('ALBUM_TOC')
@@ -432,7 +437,7 @@
-def get_discography(clientID='', userID='', artist='', rangeStart=1, rangeEnd=10):
+def get_discography(clientID='', userID='', lang='', artist='', rangeStart=1, rangeEnd=10):
"""
Queries the Gracenote service for all albums containing an artist
"""
@@ -449,6 +454,7 @@
query = _gnquery()
query.addAuth(clientID, userID)
+ query.addLang(lang)
query.addQuery('ALBUM_SEARCH')
query.addQueryTextField('ARTIST', artist)
query.addQueryOption('SELECT_EXTENDED', 'COVER,REVIEW,ARTIST_BIOGRAPHY,ARTIST_IMAGE,ARTIST_OET,MOOD,TEMPO')
@@ -534,7 +540,7 @@
return discography
-def fetch(clientID='', userID='', GNID=''):
+def fetch(clientID='', userID='', GNID='', lang=''):
"""
Fetches a track or album by GN ID
"""
@@ -551,6 +557,7 @@
query = _gnquery()
query.addAuth(clientID, userID)
+ query.addLang(lang)
query.addQuery('ALBUM_FETCH')
query.addQueryGNID(GNID)
query.addQueryOption('SELECT_EXTENDED', 'COVER,REVIEW,ARTIST_BIOGRAPHY,ARTIST_IMAGE,ARTIST_OET,MOOD,TEMPO')
@@ -721,6 +728,10 @@
client.text = clientID
user.text = userID
+ def addLang(self, language):
+ lang = xml.etree.ElementTree.SubElement(self.root, 'LANG')
+ lang.text = language
+
def addQuery(self, cmd):
query = xml.etree.ElementTree.SubElement(self.root, 'QUERY')
query.attrib['CMD'] = cmd
This will add a lang option to each parameter.
In the previous example ...
res = beautiful(pygn.search(clientID=clientID, userID=userID, lang='ja' album='Oh! Rival', artist='Porno graffiti'))
It's like that. Even if it comes back in Japanese, the mood and so on will only be in Japanese ... Tab insertion doesn't work, so I think it probably won't work. In that case, please add by hand.
Recommended Posts