def ask_echonest(artist_name): # get artist artist = artist.search(name = artist_name)[0] # get song song = pyechonest.song.search(artist = artist, max_duration = 240, buckets = ["id:spotify-WW"])[0] # return song id return song.get_tracks('spotify-WW')[0]
def index(req): #artist = "Weezer" s = "" s += "<!DOCTYPE html>" s += "<html>" s += "<head>" s += "<title>Harmony Generated Playlist</title>" s += "<script type='text/javascript' src='jwplayer.js'></script>" s += "<script src='https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js'></script>" s += "<script src='token.js'></script>" s += "<script src='rdio.js'></script>" s += "<link rel='stylesheet' type='text/css' href='main.css'>" s += "</head>" s += "<body>" s += "<div id='header'>" s += "<h1>Harmony Generated Playlist</h1>" s += "<a href='http://the.echonest.com'><img src='en-powered.gif' alt='Powered by the Echo Nest' /></a><br />" s += "</div>" #s += "Powered by <a href='http://www.rdio.com/'>Rdio®</a><br /><br />" form = util.FieldStorage(req, keep_blank_values=1) artist = form.getfirst("artist") #s += str(myparameter) song = getSong(artist) track = song.get_tracks("7digital")[0] s += "ARTIST: " + artist + "<br />" s += "SONG TITLE: " + song.title + "<br /><br />" #s += str(track) + "<br /><br />" #s += "MP3: " + track['preview_url'] + "<br /><br />" # Album Art s += "<img src='" + track['release_image'] + "' />" # MP3 player for seed song s += "<div id='mediaspace'>This text will be replaced</div>" s += """<script type='text/javascript'> jwplayer('mediaspace').setup({ 'flashplayer': 'player.swf', 'file': '""" + track['preview_url'] + """', 'controlbar': 'bottom', 'width': '470', 'height': '24' }); </script>""" # Print chord progression s += "<br />" s += "Chord Progression: " chordProgression = getChordProgression(track) s += "<div id='chord-progression'>" for i in range(len(chordProgression)): s += chordProgression[i]['name'] if i != len(chordProgression) - 1: s += " - " s += "</div>" # Playlist playlist = makePlaylist(artist, chordProgression) s += "<br />" for i in range(len(playlist)): s += "<div class='playlist-item'>" if playlist[i]['image'] != "NOT FOUND": s += "<div class='image'>" s += "<img src='" + playlist[i]['image'] + "' />" s += "</div>" else : s += "<div class='image'>" s += " " s += "</div>" s += "<div class='info'>" s += "Artist: " + playlist[i]['artist'] + "<br />" s += "Title: " + playlist[i]['title'] + "<br />" s += "Key: " + keys[playlist[i]['key']] if playlist[i]['mode'] == 1: s += " major" else: s += " minor" s += "<br />" # player #s += playlist[i]['rdio'] + "<br />" #s += "<div id='player_" + str(i) + "'>This text will be replaced</div>" #s += """<script type='text/javascript'> #var flashvars = { # 'playbackToken': playback_token, // from token.js # 'domain': domain, // from token.js # 'listener': 'callback_object' // the global name of the object that will receive callbacks from the SWF # }; # var params = { # 'allowScriptAccess': 'always' # }; # var attributes = {}; # swfobject.embedSWF('http://www.rdio.com/api/swf/', // the location of the Rdio Playback API SWF # 'player_""" + str(i) + """', // the ID of the element that will be replaced with the SWF # 1, 1, '9.0.0', 'expressInstall.swf', flashvars, params, attributes); # # </script>""" if playlist[i]['mp3'] != "NOT FOUND": s += "<div id='player_" + str(i) + "'>This text will be replaced</div>" s += """<script type='text/javascript'> jwplayer('player_""" + str(i) + """').setup({ 'flashplayer': 'player.swf', 'file': '""" + playlist[i]['mp3'] + """', 'controlbar': 'bottom', 'width': '470', 'height': '24' }); </script>""" s += "</div><!-- /.info -->" s += "</div><!-- /.playlist-item -->" #s += str(playlist) s += "</body>" s += "</html>" return s
def application(environ, start_response): s = "" s += "<!DOCTYPE html>" s += "<html>" s += "<head>" s += "<title>Harmony Generated Playlist</title>" s += "<script type='text/javascript' src='jwplayer.js'></script>" s += "<script src='https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js'></script>" s += "<link rel='stylesheet' type='text/css' href='main.css'>" s += "</head>" s += "<body>" s += "<div id='header'>" s += "<h1>Harmony Generated Playlist</h1>" s += "<a href='http://the.echonest.com'><img src='en-powered.gif' alt='Powered by the Echo Nest' /></a><br />" s += "</div>" queryParams = parse_qs(environ['QUERY_STRING']) artist = escape(queryParams.get('artist', [''])[0]) sim = escape(queryParams.get('sim', [''])[0]) if sim == "": sim = "0" if artist == "": artist = "Weezer" song = getSong(artist) songTitle = escape(queryParams.get('song', [''])[0]) if isinstance(artist, types.StringType): song = getSong2(artist, songTitle) track = song.get_tracks("7digital-US")[0] s += "<div id='info-container'>" s += "<div id='info-left'>" s += "ARTIST: " + song.artist_name + "<br />" s += "SONG TITLE: " + song.title + "<br /><br />" # Album Art s += "<img src='" + track['release_image'] + "' />" # MP3 player for seed song s += "<div id='mediaspace'>This text will be replaced</div>" s += """<script type='text/javascript'> jwplayer('mediaspace').setup({ 'flashplayer': 'player.swf', 'file': '""" + track['preview_url'] + """', 'controlbar': 'bottom', 'width': '470', 'height': '24' }); </script>""" s += "</div><!-- /#info-left -->" s += "<div id='info-right'>" s += "<h2>How It Works</h2>" s += "<ul>" s += "<li>Get seed artist from ?artist param (default Weezer)</li>" s += "<li>Select random song from catalog (or from ?song)</li>" s += "<li>Get audio analysis from Echo Nest</li>" s += "<li>Get chroma vectors</li>" s += "<li>Compare chroma vectors to chord dictionary</li>" s += "<li>Use cosine similarity - choose closest</li>" s += "<li>For each chord, select a song in that key</li>" s += "<li>If chord = D maj, song key = D major</li>" s += "<li>Select songs from similar artists only</li>" s += "<li>Compile playlist</li>" s += "</ul>" s += "</div><!-- /#info-right -->" s += "</div><!-- /#info-container -->" # Print chord progression s += "<br />" s += "Chord Progression: " chordProgression = getChordProgression(track) s += "<div id='chord-progression'>" for i in range(len(chordProgression)): s += chordProgression[i]['name'] if sim == "1": s += "<small>(" + str(chordProgression[i]['sim'] * 100) + "% )</small>" if i != len(chordProgression) - 1: s += " - " s += "</div>" # Playlist playlist = makePlaylist(artist, chordProgression) s += "<br />" for i in range(len(playlist)): s += "<div class='playlist-item'>" if playlist[i]['image'] != "NOT FOUND": s += "<div class='image'>" s += "<img src='" + playlist[i]['image'] + "' />" s += "</div>" else : s += "<div class='image'>" s += " " s += "</div>" s += "<div class='info'>" s += "Artist: " + playlist[i]['artist'] + "<br />" s += "Title: " + playlist[i]['title'] + "<br />" s += "Key: " + keys[playlist[i]['key']] if playlist[i]['mode'] == 1: s += " major" else: s += " minor" s += "<br />" if playlist[i]['mp3'] != "NOT FOUND": s += "<div id='player_" + str(i) + "'>This text will be replaced</div>" s += """<script type='text/javascript'> jwplayer('player_""" + str(i) + """').setup({ 'flashplayer': 'player.swf', 'file': '""" + playlist[i]['mp3'] + """', 'controlbar': 'bottom', 'width': '470', 'height': '24' }); </script>""" s += "</div><!-- /.info -->" s += "</div><!-- /.playlist-item -->" s += "</body>" s += "</html>" response_body = s status = '200 OK' response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(response_body)))] start_response(status, response_headers) return [bytes(response_body)]