# HG changeset patch # User Yading Song # Date 1366481546 -7200 # Node ID ed610a0bbf8350919d507d4d16328bd3f86a4700 # Parent e939a5aac00b9bd0771dec2c98052583a3923b69 Add files diff -r e939a5aac00b -r ed610a0bbf83 index.html --- /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 @@ + + + + + BrutalizeMe + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+

BrutalizeMe

+ +

Do it

+ +
+
+ +
+ + +
+ +
+ + + +
+ +
+ + + +
+ + + + + + + + + + diff -r e939a5aac00b -r ed610a0bbf83 musixmatch-master/Wake_Me_Up_When September_Ends.mp3 Binary file musixmatch-master/Wake_Me_Up_When September_Ends.mp3 has changed diff -r e939a5aac00b -r ed610a0bbf83 musixmatch-master/time.html --- /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 @@ + + + + +
\ No newline at end of file diff -r e939a5aac00b -r ed610a0bbf83 start.py --- /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 = ''' Here are the music
''' + + html_tail = '''
Back ''' + content = ''' You have chosen %s music" ''' %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 + '''

''' % audio_url + ''' %s ''' % artist + ''' %s


''' % 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 + '''

''' % audio_url + ''' %s ''' % artist + ''' %s


''' % title + + except: + pass + + + return html_head, content, html_tail + + @cp.expose + def testpage(self): + return " You have accessed the test page " + +""""*********************************************************************************""" +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: + + + + http://previews.7digital.com/clips/34/6804688.clip.mp3 + + + + 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()