changeset 9:ed610a0bbf83

Add files
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Sat, 20 Apr 2013 20:12:26 +0200
parents e939a5aac00b
children 6840f77b83aa
files index.html musixmatch-master/Wake_Me_Up_When September_Ends.mp3 musixmatch-master/time.html start.py
diffstat 4 files changed, 434 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/index.html	Sat Apr 20 20:12:26 2013 +0200
@@ -0,0 +1,120 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>BrutalizeMe</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <meta name="description" content="">
+    <meta name="author" content="">
+
+    <!-- Le styles -->
+    <link href="css/bootstrap.css" rel="stylesheet">
+    <style type="text/css">
+        body {
+            padding-top: 20px;
+            padding-bottom: 40px;
+        }
+
+            /* Custom container */
+        .container-narrow {
+            margin: 0 auto;
+            max-width: 700px;
+        }
+
+        .container-narrow > hr {
+            margin: 30px 0;
+        }
+
+            /* Main marketing message and sign up button */
+        .jumbotron {
+            margin: 60px 0;
+            text-align: center;
+        }
+
+        .jumbotron h1 {
+            font-size: 72px;
+            line-height: 1;
+        }
+
+        .jumbotron .btn {
+            font-size: 21px;
+            padding: 14px 24px;
+        }
+
+            /* Supporting marketing content */
+        .marketing {
+            margin: 60px 0;
+        }
+
+        .marketing p + h4 {
+            margin-top: 28px;
+        }
+    </style>
+    <link href="css/bootstrap-responsive.css" rel="stylesheet">
+
+    <!-- Fav and touch icons -->
+    <link rel="shortcut icon" href="../assets/ico/favicon.ico">
+    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
+    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
+    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
+    <link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
+    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css"/>
+    <link rel="stylesheet" href="css/styles.css"/>
+    <script src="js/jquery.min.js"></script>
+    <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
+    <script type="text/javascript" src="js/main.js"></script>
+    <script type="text/javascript" src="js/infoSongs.js"></script>
+    <script type="text/javascript" src="js/genre.js"></script>
+
+
+
+</head>
+
+<body>
+<div id="dz-root"></div>
+<div class="container-narrow">
+
+    <hr>
+
+    <div class="jumbotron">
+        <h1>BrutalizeMe</h1>
+
+        <p class="lead">Do it</p>
+
+    </div>
+    <hr>
+
+    <div class="row-fluid marketing centerIcon">
+        <div class="span12 centerIcon" id="buttonDiv">
+            <a class="btn btn-large btn-success " onclick="lookProfile()" id="buttonSelect" href="#">Search a
+                friend!</a>
+        </div>
+
+        <div class="span12 centerIcon">
+
+        </div>
+
+        <div class="span12 centerIcon" id="buttonCreateDiv">
+            <a class="btn btn-large btn-success " onclick="showPlaylist()" id="buttonCreate" href="#">Create Playlist!</a>
+        </div>
+
+    </div>
+
+    <hr>
+
+    <div class="footer">
+        <p></p>
+    </div>
+
+</div>
+<!-- /container -->
+
+<!-- Le javascript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+
+<script src="js/bootstrap.js"></script>
+
+
+</body>
+</html>
Binary file musixmatch-master/Wake_Me_Up_When September_Ends.mp3 has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/musixmatch-master/time.html	Sat Apr 20 20:12:26 2013 +0200
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="application/javascript"></script>
+<script type="application/javascript">
+
+var accessId = 'bc59492a-d127-487b-acb4-c2e4226b34cb';
+var taskUrl = 'process/elastique';
+var parameters = { blocking: false, format: 'json', access_id: accessId };
+
+// the values for these parameters were taken from the corresponding controls in the demo form
+parameters['input_file'] = 'Wake_Me_Up_When September_Ends.mp3';
+parameters['pitch_semitones'] = '0';
+parameters['tempo_factor'] = '2';
+parameters['formant_semitones'] = '0';
+    
+function onTaskStarted(data) {
+    var fileId = data.file.file_id;
+    
+    // request task progress every 500ms
+    var polling = setInterval(pollTaskProgress, 500);
+   
+    function pollTaskProgress() {
+        $.ajax({ url: 'https://api.sonicAPI.com/file/status?file_id=' + fileId + '&access_id=' + accessId + '&format=json', 
+                 crossDomain: true, success: function(data) {
+            if (data.file.status == 'ready') {
+                onTaskSucceeded(fileId);
+                clearInterval(polling);
+            } else if (data.file.status == 'working') {
+                $('#result').text(data.file.progress + '% done');
+            }
+        }});
+    }
+}
+
+function onTaskSucceeded(fileId) {
+    // create HTML5 audio player
+    var downloadUrl = 'https://api.sonicAPI.com/file/download?file_id=' + fileId + '&access_id=' + accessId + '&format=mp3-cbr';
+    var audio = '<audio src="' + downloadUrl + '" controls="controls" autoplay="autoplay">';
+    
+    $('#result').html(audio);
+}
+
+function onTaskFailed(response) {
+    var data = $.parseJSON(response.responseText);
+    var errorMessages = data.errors.map(function(error) { return error.message; });
+ 
+    $('#result').text('Task failed, reason: ' + errorMessages.join(','));
+}
+
+// start task when clicking on the "Start task" button
+$(document).ready(function() {
+    $('#start').click(function() {
+    	// execute an HTTP GET using the task's URL, the parameters and callback functions defined above
+        $.ajax({ url: 'https://api.sonicAPI.com/' + taskUrl, data: parameters, 
+                 success: onTaskStarted, error: onTaskFailed, crossDomain: true });
+    });
+});
+</script>
+<input type="button" id="start" value="Start task" />
+<div id="result" />
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/start.py	Sat Apr 20 20:12:26 2013 +0200
@@ -0,0 +1,255 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+"""
+Created by Yading Song on 2013-04-21 for Music Hack Day in Paris
+Copyright (c) 2013 . All rights reserved.
+"""
+
+import os,sys,optparse,signal,time,math
+import cherrypy as cp
+
+from cherrypy.lib import static
+import subprocess as sp
+from subprocess import Popen as spopen
+
+
+""""*********************************************************************************"""
+
+from xml.dom import minidom
+import urllib2 #call url function
+import os 
+import sys
+import cPickle
+
+import pyechonest # import echonest API 
+from pyechonest import artist, catalog, config, playlist # How it works instead of pyechonest
+import pylast # import last.fm API
+
+#change the path to 7-digital python library
+sys.path.append("./7digital-python/lib/")
+import py7digital
+
+
+
+
+# this is just a parser for command line options for the server.
+op = optparse.OptionParser()
+op.add_option('-u', '--user', action="store", dest="USER", default="devel", type="str")
+options, args = op.parse_args()
+CONFIG_FILE = "%(USER)s.cfg" %options.__dict__
+
+if not os.path.isfile(CONFIG_FILE) :
+	print >> sys.stderr, "Config file not found: %s" %CONFIG_FILE
+	sys.exit(-1)
+
+# This is the server side of the actual Web-application
+class ServerExample:
+	
+	def __init__(self):
+		self.inputs = []
+	
+	def index(self):
+		return ""
+	
+	@cp.expose
+	def receiveinput(self, userinput):
+            print "\n\n >>>The user entered the text: %(userinput)s\n\n" %locals()
+            
+            tags = network.search_for_tag(userinput)
+            tags_search = tags.get_next_page()
+        
+            # suppose we have got the keywords that user typed in
+                
+            # preset 
+            html_head = '''<html> <body> Here are the music <br /> ''' 
+                            
+            html_tail = '''<script type="text/javascript" src="http://mediaplayer.yahoo.com/js"></script><br /> <a href="javascript: history.go(-1)">Back</a> </body> </html>'''
+            content = '''<h> You have chosen <b> %s </b> music" </h>''' %userinput
+            audio_url = ""
+            
+            # choose the top 3 tags with the key word
+            for item in tags_search[1:3]: 
+                tag_object = network.get_tag(item)
+                track_info = tag_object.get_top_tracks()
+                
+                # choose the top 3 tracks with the chosen key word
+                for tracks in track_info[1:5]:
+                  
+                    track_detail = ''' %s%s ''' %tracks
+                    track_detail = track_detail.strip().rstrip('0')
+                    artist, title = track_detail.split('-')
+    
+                    # the title and the artist have been found 
+                     
+                    try:
+                        
+                        _, trackid = get_trackid_from_text_search(title,artist)	
+                        
+                        if trackid is not None:
+                            audio_url = get_preview_from_trackid(trackid)    
+                        
+                            content = content + '''<p><a href=" %s ">''' % audio_url + '''<b> %s </b>''' % artist + '''<b> %s </b> </a></p><br /> ''' % title 
+        
+                    except:            
+                            try:
+                                (tracktitle,trackid) = get_trackid_from_text_search(title,'')	
+
+                                if trackid is not None:
+                                    audio_url = get_preview_from_trackid(trackid)  
+                                    
+                                    content = content + '''<p><a href=" %s ">''' % audio_url + '''<b> %s </b>''' % artist + '''<b> %s </b> </a></p><br /> ''' % title 
+                            
+                            except:
+                                pass
+                                    
+                    
+            return html_head, content, html_tail
+
+	@cp.expose
+	def testpage(self):
+		return "<html> <body> You have accessed the test page </body> </html>"
+
+""""*********************************************************************************"""
+def url_call(url):
+    """
+        ***This method is from get_preview_url.py by Thierry Bertin-Mahieux***
+        Do a simple request to the 7digital API
+        We assume we don't do intense querying, this function is not robust
+        Return the answer as an xml document
+        """
+    stream = urllib2.urlopen(url)
+    xmldoc = minidom.parse(stream).documentElement
+    stream.close()
+    return xmldoc
+
+""""*********************************************************************************"""
+
+def get_preview_from_trackid(trackid):
+    """
+        ***This method is from get_preview_url.py by Thierry Bertin-Mahieux***
+        Ask for the preview to a particular track, get the XML answer
+        After calling the API with a given track id,
+        we get an XML response that looks like:
+        
+        <response status="ok" version="1.2" xsi:noNamespaceSchemaLocation="http://api.7digital.com/1.2/static/7digitalAPI.xsd">
+        <url>
+        http://previews.7digital.com/clips/34/6804688.clip.mp3
+        </url>
+        </response>
+        
+        We parse it for the URL that we return, or '' if a problem
+        """
+    url = 'http://api.7digital.com/1.2/track/preview?redirect=false'
+    url += '&trackid='+str(trackid)
+    url += '&oauth_consumer_key='+DIGITAL7_API_KEY
+    xmldoc = url_call(url)
+    status = xmldoc.getAttribute('status')
+    if status != 'ok':
+        return ''
+    urlelem = xmldoc.getElementsByTagName('url')[0]
+    preview = urlelem.firstChild.nodeValue
+    return preview   
+
+""""*********************************************************************************"""
+
+def get_trackid_from_text_search(title,artistname=''):
+    """
+        ***This method is from get_preview_url.py by Thierry Bertin-Mahieux***
+        Search for an artist + title using 7digital search API
+        Return None if there is a problem, or tuple (title,trackid)
+        """
+    url = 'http://api.7digital.com/1.2/track/search?'
+    url += 'oauth_consumer_key='+DIGITAL7_API_KEY
+    query = title
+    if artistname != '':
+        query = artistname + ' ' + query
+    query = urllib2.quote(query)
+    url += '&q='+query
+    xmldoc = url_call(url)
+    status = xmldoc.getAttribute('status')
+    if status != 'ok':
+        return None
+    resultelem = xmldoc.getElementsByTagName('searchResult')
+    if len(resultelem) == 0:
+        return None
+    track = resultelem[0].getElementsByTagName('track')[0]
+    tracktitle = track.getElementsByTagName('title')[0].firstChild.data
+    trackid = int(track.getAttribute('id'))
+    return (tracktitle,trackid)  
+
+""""*********************************************************************************"""
+
+
+def getProcessPids(port,kill=False):
+	'''Get the pid of the offending Python process given a port after an unsuccessful restart.'''
+	print "Running lsof -i :"+str(port)," ...\n\n"
+	command = "lsof -i :"+str(port)
+	w = spopen(command,stdout=sp.PIPE,stderr=sp.PIPE,shell=True)
+	se = w.stderr.readlines()
+	result = w.stdout.readlines()
+	exitcode = w.wait()
+	if not result : 
+		print "getProcessPid:: Unable to obtain process pid. (lsof returned nothing. exitcode: %s)" %str(exitcode)
+		return False
+	import pprint
+	pprint.pprint(result)
+	
+	# get heading:
+	ix = None
+	head = result[0].upper()
+	if 'PID' in head:
+		head = filter(lambda x: x != str(), head.split(' '))
+		head = map(lambda x: x.strip().replace(' ',''), head)
+		if 'PID' in head : ix = head.index('PID')
+	# get process pid
+	pids = []
+	for line in result :
+		if 'python' in line.lower() :
+			line = filter(lambda x: x != str(), line.split(' '))
+			line = map(lambda x: x.strip().replace(' ',''), line)
+			try :
+				if ix : 
+					pids.append(int(line[ix]))
+				else:
+					numbers = filter(lambda x: x.isdigit(), line)
+					pids.append(int(numbers[0]))
+			except:
+				print 'Error parsing lsof results.' 
+				return False
+	print 'Pids found: ',pids
+	# kill if specified
+	if kill :
+		pids_killed = []
+		import signal
+		for pid in pids:
+			print 'Killing process: ',pid
+			try :
+				os.kill(pid,signal.SIGKILL)
+				pids_killed.append(pid)
+			except :
+				print 'Failed: ',pid
+		if pids_killed :
+			print 'Processes killed:',pids_killed,' Waiting 10 seconds...'
+			import time
+			time.sleep(10)
+			return True
+	return False
+
+
+def main(argv=None):
+	
+	# Configure and start
+	
+
+	cp.config.update(CONFIG_FILE)
+	cp.config.update({'tools.staticdir.root': os.getcwd()})
+	cp.tree.mount(ServerExample(),script_name="/yading",config=CONFIG_FILE)	
+	port = int(cp.server.socket_port)
+	ip = cp.server.socket_host
+	print "Trying to bind: %(ip)s:%(port)s" %locals()
+	getProcessPids(port,kill=True)
+	cp.quickstart()
+
+if __name__ == "__main__":
+	main()