Exemplo n.º 1
0
 def do_cache(self):
     url = get_http_param(request, "url")
     if not url:
         self.log.debug("No Url")
         return "NO URL", 404
     self.log.debug("Url is %s" % str(url))
     try:
         file_path, stream, resource_type = get_resource(self, url)
         if not stream:
             self.log.debug("Url %s: no stream" % str(url))
             return "NO STREAM", 404
         if resource_type == 'mp3':
             _type = 'audio/mp3'
         elif resource_type == 'wav':
             _type = 'audio/wav'
         elif resource_type == 'grxml':
             _type = 'application/srgs+xml'
         elif resource_type == 'jsgf':
             _type = 'application/x-jsgf'
         else:
             self.log.debug("Url %s: not supported format" % str(url))
             return "NOT SUPPORTED FORMAT", 404
         self.log.debug("Url %s: stream found" % str(url))
         return flask.Response(response=stream,
                               status=200,
                               headers=None,
                               mimetype=_type,
                               content_type=_type,
                               direct_passthrough=False)
     except Exception, e:
         self.log.error("/Cache/ Error: %s" % str(e))
         [ self.log.error('/Cache/ Error: %s' % line) for line in \
                         traceback.format_exc().splitlines() ]
         raise e
Exemplo n.º 2
0
 def do_cache(self):
     url = get_http_param(request, "url")
     if not url:
         self.log.debug("No Url")
         return "NO URL", 404
     self.log.debug("Url is %s" % str(url))
     try:
         file_path, stream, resource_type = get_resource(self, url)
         if not stream:
             self.log.debug("Url %s: no stream" % str(url))
             return "NO STREAM", 404
         if resource_type == 'mp3':
             _type = 'audio/mp3'
         elif resource_type == 'wav':
             _type = 'audio/wav'
         elif resource_type == 'grxml':
             _type = 'application/srgs+xml'
         elif resource_type == 'jsgf':
             _type = 'application/x-jsgf'
         else:
             self.log.debug("Url %s: not supported format" % str(url))
             return "NOT SUPPORTED FORMAT", 404
         self.log.debug("Url %s: stream found" % str(url))
         return flask.Response(response=stream, status=200,
                               headers=None, mimetype=_type,
                               content_type=_type,
                               direct_passthrough=False)
     except Exception, e:
         self.log.error("/Cache/ Error: %s" % str(e))
         [ self.log.error('/Cache/ Error: %s' % line) for line in \
                         traceback.format_exc().splitlines() ]
         raise e
Exemplo n.º 3
0
    def get_wav(self):
        self.log.debug("RESTAPI GetWav called")
        result = False
        name = get_post_param(request, "WavName") 

        if not name: name = get_http_param(request, "WavName")
        if not name:
            msg = "WavName parameter missing"
            return self.send_response(Success=result, Message=msg)

        if not check_for_wav(name):
            msg = "WAV %s is invalid or does not exist" % name
            return self.send_response(Success=result, Message=msg)

        result = True
        msg = "WAV %s exists" % name
        return flask.send_file(name)
Exemplo n.º 4
0
 def do_cache_type(self):
     url = get_http_param(request, "url")
     if not url:
         self.log.debug("No Url")
         return "NO URL", 404
     self.log.debug("Url is %s" % str(url))
     try:
         resource_type = get_resource_type(self, url)
         if not resource_type:
             self.log.debug("Url %s: no type" % str(url))
             return "NO TYPE", 404
         self.log.debug("Url %s: type is %s" % (str(url), str(resource_type)))
         return flask.jsonify(CacheType=resource_type)
     except Exception, e:
         self.log.error("/CacheType/ Error: %s" % str(e))
         [ self.log.error('/CacheType/ Error: %s' % line) for line in \
                         traceback.format_exc().splitlines() ]
         raise e
Exemplo n.º 5
0
    def check_wav(self):
        self.log.debug("RESTAPI CheckWav called")
        result = False
        name = get_post_param(request, "WavName") 

        if not name: name = get_http_param(request, "WavName")
        if not name:
            msg = "WavName parameter missing"
            return self.send_response(Success=result, Message=msg)

        fullpath = re_root(name, self.save_dir)
        if not check_for_wav(fullpath):
            msg = "WAV %s is invalid or does not exist" % name
            return self.send_response(Success=result, Message=msg)

        result = True
        msg = "WAV %s exists" % name
        return self.send_response(Success=result, Message=msg, Name=name)