Esempio n. 1
0
    def analyze(self, id, callback=None, _=""):
        cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
        if callback:
            cherrypy.response.headers["Content-Type"] = "text/javascript"
        else:
            cherrypy.response.headers["Content-Type"] = "application/json"
        print id
        self.cache["total_calls"] += 1
        if id in self.cache:
            result = {"status": "OK", "trid": self.cache[id]}
        else:
            if id.find("http") >= 0:
                js = self.resolve(id)
            else:
                url = "http://api.soundcloud.com/tracks/%s.json?client_id=%s" % (id, self.sc_client_id)
                r = requests.get(url)
                js = r.json()

            if "stream_url" in js:
                url = js["stream_url"] + "?client_id=" + self.sc_client_id
                result = self.en.post("track/upload", url=url)
                if result["status"]["code"] == 0:
                    trid = result["track"]["id"]
                    self.add_entry(js, trid)
                    result = {"status": "OK", "trid": trid}
            else:
                result = {"status": "ERROR", "message": "no audio"}
        return webtools.to_json(result, callback)
Esempio n. 2
0
 def stats(self, callback=None, _=""):
     cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
     if callback:
         cherrypy.response.headers["Content-Type"] = "text/javascript"
     else:
         cherrypy.response.headers["Content-Type"] = "application/json"
     self.cache["total_calls"] += 1
     results = {"status": "OK", "calls": self.cache["total_calls"], "ids": len(self.cache)}
     return webtools.to_json(results, callback)
Esempio n. 3
0
    def artists(self, id='', count='10', callback=None, _=''):
        if callback:
            cherrypy.response.headers['Content-Type']= 'text/javascript'
        else:
            cherrypy.response.headers['Content-Type']= 'application/json'

        count = int(count)
        ids = get_param_as_list(id)

        results = []
        for id in ids:
            results.append( self.get_artist_info(id, count) )
        return webtools.to_json(results, callback)
Esempio n. 4
0
    def artists(self, id='', count='10', callback=None, _=''):
        if callback:
            cherrypy.response.headers['Content-Type'] = 'text/javascript'
        else:
            cherrypy.response.headers['Content-Type'] = 'application/json'

        count = int(count)
        ids = get_param_as_list(id)

        results = []
        for id in ids:
            results.append(self.get_artist_info(id, count))
        return webtools.to_json(results, callback)