# Copyright (C) 2025 AIDC-AI # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ Editor API schemas for timeline editor """ from pydantic import BaseModel, Field from typing import List, Optional from datetime import datetime class StoryboardFrameSchema(BaseModel): """Schema for a single storyboard frame""" id: str index: int order: int narration: str image_prompt: Optional[str] = None image_path: Optional[str] = None audio_path: Optional[str] = None video_segment_path: Optional[str] = None duration: float = 0.0 class Config: from_attributes = True class StoryboardSchema(BaseModel): """Schema for complete storyboard""" id: str title: str frames: List[StoryboardFrameSchema] total_duration: float final_video_path: Optional[str] = None created_at: Optional[datetime] = None class Config: from_attributes = True class ReorderFramesRequest(BaseModel): """Request to reorder frames""" order: List[str] = Field(..., description="List of frame IDs in new order") class UpdateDurationRequest(BaseModel): """Request to update frame duration""" duration: float = Field(..., ge=0.1, le=60.0, description="New duration in seconds") class PreviewRequest(BaseModel): """Request to generate preview""" start_frame: int = Field(0, ge=0, description="Start frame index") end_frame: Optional[int] = Field(None, description="End frame index (None = to end)") class PreviewResponse(BaseModel): """Response with preview video path""" preview_path: str duration: float frames_count: int class UpdateFrameRequest(BaseModel): """Request to update frame content""" narration: Optional[str] = Field(None, description="Updated narration text") image_prompt: Optional[str] = Field(None, description="Updated image generation prompt") class UpdateFrameResponse(BaseModel): """Response after updating frame""" id: str narration: str image_prompt: Optional[str] updated: bool = True class RegenerateImageRequest(BaseModel): """Request to regenerate frame image""" image_prompt: Optional[str] = Field(None, description="Override prompt for regeneration") class RegenerateImageResponse(BaseModel): """Response after regenerating image""" image_path: str success: bool = True class RegenerateAudioRequest(BaseModel): """Request to regenerate frame audio""" narration: Optional[str] = Field(None, description="Override narration for regeneration") voice: Optional[str] = Field(None, description="Voice to use for TTS") class RegenerateAudioResponse(BaseModel): """Response after regenerating audio""" audio_path: str duration: float success: bool = True class InpaintRequest(BaseModel): """Request to inpaint (局部重绘) frame image""" mask: str = Field(..., description="Base64 encoded mask image (white=inpaint, black=keep)") prompt: Optional[str] = Field(None, description="Optional prompt for inpainted region") denoise_strength: float = Field(0.8, ge=0.0, le=1.0, description="Denoise strength (0.0-1.0)") class InpaintResponse(BaseModel): """Response after inpainting""" image_path: str success: bool = True class ExportRequest(BaseModel): """Request to export edited video""" bgm_path: Optional[str] = Field(None, description="Background music path") bgm_volume: float = Field(0.2, ge=0.0, le=1.0, description="BGM volume (0.0-1.0)") class ExportResponse(BaseModel): """Response for export request""" task_id: str status: str = "pending" class ExportStatusResponse(BaseModel): """Response for export status check""" task_id: str status: str # pending, processing, completed, failed progress: float = 0.0 # 0.0 to 1.0 video_path: Optional[str] = None download_url: Optional[str] = None error: Optional[str] = None class AlignPromptRequest(BaseModel): """Request to align image prompt with narration""" narration: Optional[str] = Field(None, description="Override narration text") class AlignPromptResponse(BaseModel): """Response after aligning prompt""" image_prompt: str success: bool = True