7 sys.path.append(
"7digital-python/lib/")
11 from xml.dom
import minidom
15 newapikey =
'82be3ea3f79ea404d45f47607c103eff' 21 song_wakeMeUp = musixmatch.ws.track.search(q_lyrics =
'wake me up',f_lyrics_language=
'en',s_track_rating=
'desc',format =
'json',apikey=newapikey)
40 DIGITAL7_API_KEY =
'7dbpa63h3y3d' 44 ***This method is from get_preview_url.py by Thierry Bertin-Mahieux*** 45 Do a simple request to the 7digital API 46 We assume we don't do intense querying, this function is not robust 47 Return the answer as na xml document 49 stream = urllib2.urlopen(url)
50 xmldoc = minidom.parse(stream).documentElement
57 mp3file = urllib2.urlopen(file_url)
60 local_file = open(file_name,
"wb")
62 local_file.write(mp3file.read())
65 """"*********************************************************************************""" 69 ***This method is from get_preview_url.py by Thierry Bertin-Mahieux*** 70 Search for an artist + title using 7digital search API 71 Return None if there is a problem, or tuple (title,trackid) 73 url =
'http://api.7digital.com/1.2/track/search?' 74 url +=
'oauth_consumer_key='+DIGITAL7_API_KEY
77 query = artistname +
' ' + query
78 query = urllib2.quote(query)
81 status = xmldoc.getAttribute(
'status')
84 resultelem = xmldoc.getElementsByTagName(
'searchResult')
85 if len(resultelem) == 0:
87 track = resultelem[0].getElementsByTagName(
'track')[0]
88 tracktitle = track.getElementsByTagName(
'title')[0].firstChild.data
89 trackid = int(track.getAttribute(
'id'))
90 return (tracktitle,trackid)
95 ***This method is from get_preview_url.py by Thierry Bertin-Mahieux*** 96 Ask for the preview to a particular track, get the XML answer 97 After calling the API with a given track id, 98 we get an XML response that looks like: 100 <response status="ok" version="1.2" xsi:noNamespaceSchemaLocation="http://api.7digital.com/1.2/static/7digitalAPI.xsd"> 102 http://previews.7digital.com/clips/34/6804688.clip.mp3 106 We parse it for the URL that we return, or '' if a problem 108 url =
'http://api.7digital.com/1.2/track/preview?redirect=false' 109 url +=
'&trackid='+str(trackid)
110 url +=
'&oauth_consumer_key='+DIGITAL7_API_KEY
112 status = xmldoc.getAttribute(
'status')
115 urlelem = xmldoc.getElementsByTagName(
'url')[0]
116 preview = urlelem.firstChild.nodeValue
120 for each_song
in song_wakeMeUp[
'body'][
'track_list']:
121 print each_song[
'track'][
'track_name'] +
'\t' + each_song[
'track'][
'artist_name']
127 file_name = tracktitle +
u'.mp3' 128 file_name = file_name.replace(
u'/',
u' ')
134 path_name =
'./' + file_name
def download_file(file_url, file_name)
def get_preview_from_trackid(trackid)
def get_trackid_from_text_search(title, artistname='')