| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #!/usr/bin/env python3
- from constants import BASE_PATH,PORT
- import datetime
- import json
- import tasks
- from db import db
- from flask import Flask, jsonify, request
- from rq import Queue
- app = Flask(__name__)
- d=db()
- @app.route(BASE_PATH + '/')
- def index():
- return "Hello world"
- @app.route(BASE_PATH + '/list/uploaded/')
- @app.route(BASE_PATH + '/list/uploaded')
- def uploaded_list():
- ret={'list': d.uploaded()}
- return jsonify(ret)
- @app.route(BASE_PATH + '/list/raw/')
- @app.route(BASE_PATH + '/list/raw')
- def raw_list():
- ret={'list': d.raw() }
- return jsonify(ret)
- @app.route(BASE_PATH + '/list/processed/')
- @app.route(BASE_PATH + '/list/processed')
- def processed_list():
- ret={'list': d.processed() }
- return jsonify(ret)
- @app.route(BASE_PATH + '/list/jobs/')
- @app.route(BASE_PATH + '/list/jobs')
- def jobs():
- working = tasks.jobs()
- return json.dumps({"working":working})
- @app.route(BASE_PATH + '/raw/<video_id>')
- def raw_file(video_id):
- ret=d.raw(video_id)
- print(ret)
- if ret is not None:
- ret["file"]=ret["file"].split("front")[1] #FIXME, path relativo al webserver
- return jsonify(ret)
- return "{}"
- @app.route(BASE_PATH + '/processed/<video_id>')
- def processed_file(video_id):
- ret=d.processed(video_id)
- ret["out_fname"]=ret["out_fname"].split("front")[1] #FIXME, path relativo al webserver
- return jsonify(ret)
- @app.route(BASE_PATH + '/crop/', methods=["POST"])
- def crop():
- ret={"status":"Procesando"}
- today=datetime.date.today()
- data = request.get_json()
- video=d.raw(data["id"])
- if "censuras" not in data:
- data["censuras"] = []
- out_filename="%s_%s_%s.mp4" % (data["curso"],
- today.strftime('%Y%m%d'),
- data["desc"])
- job = tasks.crop_video.delay(
- video["file"],
- str(data["inicio"]),
- str(data["fin"]),
- data["censuras"],
- out_filename)
- job.meta["type"]="Cortar"
- job.meta["target"]=out_filename
- job.save()
- ret["job_id"]=job.get_id()
- return jsonify(ret)
- @app.route(BASE_PATH + '/upload/', methods=["POST"])
- def upload():
- ret={"status":"Procesando"}
- today=datetime.date.today()
- data = request.get_json()
- video=data["id"]
- prof=data["prof"]
- texto1=data["texto1"]
- texto2=data["texto2"]
- if video is None or prof is None or texto1 is None or texto2 is None:
- return jsonify({"status":"Error, faltan datos"})
- tasks.upload_video(video,prof,texto1,texto2)
- return jsonify(ret)
- @app.route(BASE_PATH + '/cargar/<video_id>')
- def cargar(video_id):
- return jsonify(tasks.cargar_plataforma(video_id))
- @app.route(BASE_PATH + '/reupload/<video_id>')
- def reupload(video_id):
- today=datetime.date.today()
- data = d.videoData(video_id)
- video=data["video"]
- tsplit=data["title"].split("-")
- prof=tsplit[0]
- texto1=tsplit[1]
- texto2=tsplit[2]
- cutid = d.findCutId(video)
- tasks.upload_video(cutid,prof,texto1,texto2)
- ret={"status":"Procesando"}
- return jsonify(ret)
- @app.route(BASE_PATH + '/job')
- def job():
- job = tasks.long_job.delay("test")
- ret = {"id":job.get_id()}
- return jsonify(ret)
- @app.route(BASE_PATH+"/results/<job_key>", methods=['GET'])
- def get_results(job_key):
- try:
- ret=tasks.result(job_key)
- except Exception as e:
- print(e)
- return "Error. Probablemente job_key es invalido", 400
- return ret
- if __name__ == '__main__':
- app.run(host="0.0.0.0",port=PORT, debug=True)
|