You've already forked my-video-workflow
添加util.flask;video_clip编辑逻辑
This commit is contained in:
48
controller/api/video_clip_blueprint.py
Normal file
48
controller/api/video_clip_blueprint.py
Normal file
@ -0,0 +1,48 @@
|
||||
import os
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from util.flask import not_found_json_response, error_json_response
|
||||
from workflow.video import get_video_real_duration, duration_str_to_float
|
||||
from model import db
|
||||
from model.VideoClip import VideoClip
|
||||
|
||||
blueprint = Blueprint("api_video_clip", __name__, url_prefix="/api/video_clip")
|
||||
|
||||
|
||||
@blueprint.get("/<int:video_clip_id>")
|
||||
def get_video_clip_info(video_clip_id):
|
||||
video_clip = VideoClip.get(video_clip_id)
|
||||
if video_clip is None:
|
||||
return not_found_json_response(id=video_clip_id)
|
||||
return jsonify(video_clip.to_json())
|
||||
|
||||
|
||||
@blueprint.put("/<int:video_clip_id>")
|
||||
def modify_video_clip(video_clip_id):
|
||||
video_clip = VideoClip.get(video_clip_id)
|
||||
if video_clip is None:
|
||||
return not_found_json_response(id=video_clip_id)
|
||||
payload = request.json
|
||||
if "workflow_id" in payload:
|
||||
try:
|
||||
workflow_id = int(payload["workflow_id"])
|
||||
video_clip.workflow_id = workflow_id
|
||||
except ValueError:
|
||||
return error_json_response("workflow_id is not a int", workflow_id=payload["workflow_id"])
|
||||
if "base_path" in payload:
|
||||
if not os.path.isdir(payload["base_path"]):
|
||||
return error_json_response("base_path is not a dir", base_path=payload["base_path"])
|
||||
video_clip.base_path = payload["base_path"]
|
||||
if "file" in payload:
|
||||
if os.path.isabs(payload["file"]):
|
||||
video_clip.base_path = ""
|
||||
video_clip.file = payload["file"]
|
||||
# file exist check
|
||||
if not os.path.isfile(video_clip.full_path):
|
||||
return error_json_response("file not exist", full_path=video_clip.full_path)
|
||||
# update duration
|
||||
duration = duration_str_to_float(get_video_real_duration(video_clip.full_path))
|
||||
video_clip.duration = duration
|
||||
db.session.commit()
|
||||
return jsonify(video_clip.to_json())
|
@ -3,6 +3,7 @@ import threading
|
||||
from flask import Blueprint, jsonify
|
||||
|
||||
from model.Workflow import Workflow
|
||||
from util.flask import not_found_json_response
|
||||
from workflow.worker import do_workflow
|
||||
from model import db
|
||||
|
||||
@ -18,18 +19,36 @@ def get_workflow_list():
|
||||
@blueprint.get("/<int:workflow_id>")
|
||||
def get_workflow_info(workflow_id):
|
||||
workflow = Workflow.get(workflow_id)
|
||||
if workflow is None:
|
||||
return not_found_json_response(id=workflow_id)
|
||||
return jsonify(workflow)
|
||||
|
||||
|
||||
@blueprint.put("/<int:workflow_id>")
|
||||
def modify_workflow_info(workflow_id):
|
||||
workflow = Workflow.get(workflow_id)
|
||||
if workflow is None:
|
||||
return not_found_json_response(id=workflow_id)
|
||||
return jsonify(workflow)
|
||||
|
||||
|
||||
@blueprint.delete("/<int:workflow_id>")
|
||||
def delete_workflow(workflow_id):
|
||||
workflow = Workflow.get(workflow_id)
|
||||
if workflow is not None:
|
||||
db.session.delete(workflow)
|
||||
db.session.commit()
|
||||
return jsonify({
|
||||
"id": workflow_id,
|
||||
"old_data": workflow
|
||||
})
|
||||
|
||||
|
||||
@blueprint.post("/<int:workflow_id>/edit")
|
||||
def start_editing(workflow_id):
|
||||
workflow = Workflow.get(workflow_id)
|
||||
if workflow is None:
|
||||
response = jsonify({
|
||||
"message": "Not Found"
|
||||
})
|
||||
response.status_code = 404
|
||||
return response
|
||||
return not_found_json_response(id=workflow_id)
|
||||
workflow.editing = True
|
||||
db.session.commit()
|
||||
return jsonify(workflow.to_dict())
|
||||
@ -39,11 +58,7 @@ def start_editing(workflow_id):
|
||||
def done_editing(workflow_id):
|
||||
workflow = Workflow.get(workflow_id)
|
||||
if workflow is None:
|
||||
response = jsonify({
|
||||
"message": "Not Found"
|
||||
})
|
||||
response.status_code = 404
|
||||
return response
|
||||
return not_found_json_response(id=workflow_id)
|
||||
workflow.editing = False
|
||||
db.session.commit()
|
||||
return jsonify(workflow.to_dict())
|
||||
@ -53,11 +68,7 @@ def done_editing(workflow_id):
|
||||
def do_workflow(workflow_id):
|
||||
workflow = Workflow.get(workflow_id)
|
||||
if workflow is None:
|
||||
response = jsonify({
|
||||
"message": "Not Found"
|
||||
})
|
||||
response.status_code = 404
|
||||
return response
|
||||
return not_found_json_response(id=workflow_id)
|
||||
if len(workflow.video_clips) > 0 and len(workflow.danmaku_clips) > 0:
|
||||
threading.Thread(target=do_workflow, args=(
|
||||
workflow.video_clips[0].full_path,
|
||||
|
Reference in New Issue
Block a user