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())
|
Reference in New Issue
Block a user