Beispiel #1
0
def transcode(request):
    url = request.GET.get('url', False)
    if not url or not is_oga_url(url):
        return HttpResponse('Not a valid url', status=400)
        
    file_hash = request.GET.get('hash', False)
    mimetype = request.GET.get('mimetype', False)
    subname = request.GET.get('subname', False)
    
    job = AsyncResult(url)
    if job.successful() and job.result.successful():
        found, file_descr, asset = get_asset(job, file_hash, subname, mimetype)
        if found:
            task_id = url+file_hash+mimetype+subname+'preview'
            job = schedule(task_id, lambda: tasks.generate_preview((file_descr, asset), {'path': '/tmp/transcoded'}, task_id=task_id), request)
                
            if job.state == 'SUCCESS' and job.result:
                data = job.result
            elif job.state == 'FAILURE' and job.result:
                data = str(job.result)
            else:
                data = job.state
            data = {'state': job.state, 'result': data}
            return HttpResponse(json.dumps(data, indent=4), content_type="application/json")
        else:
            data = {'Error': 'Combination of hash, mimetype, subname not found!'}
            if settings.DEBUG:
                from thrift.protocol.TJSONProtocol import TSimpleJSONProtocol
                from damn_at.serialization import SerializeThriftMsg
                data['assets'] = [json.loads(SerializeThriftMsg(ass, TSimpleJSONProtocol)) for ass in asset]
            return HttpResponse(json.dumps(data, indent=4), content_type="application/json", status=400)
    else:
        return HttpResponse('wait for it!', status=400)
Beispiel #2
0
def analyze(request):
    url = request.GET.get('url', False)
    if not url or not is_oga_url(url):
        return HttpResponse('Not a valid url', status=400)

    job = schedule(url, lambda: tasks.oga(url, task_id=url), request)
    stats, ready = tasks.collect_stats(job.id)
    
    if ready:
        job = AsyncResult(job.id)        
        return HttpResponse(json.dumps(stats, indent=4), content_type="application/json")
    else:
        return HttpResponse(json.dumps(stats, indent=4), content_type="application/json")