fix: 模板片段信息

This commit is contained in:
root
2025-07-10 23:12:03 +08:00
parent b07992a82a
commit 629b4dd42b
3 changed files with 124 additions and 33 deletions

View File

@@ -368,6 +368,80 @@ class TemplateManager:
logger.error(f"Failed to delete template {template_id}: {e}")
return False
def get_template_detail(self, template_id: str) -> Optional[Dict[str, Any]]:
"""
Get detailed template information including tracks and segments
Args:
template_id: Template ID
Returns:
Dict containing detailed template information with tracks and segments
"""
try:
# Get basic template info
template = self.get_template(template_id)
if not template:
return None
# Load draft content to get tracks and segments
draft_content_path = Path(template.draft_content_path)
if not draft_content_path.exists():
logger.error(f"Draft content file not found: {draft_content_path}")
return None
with open(draft_content_path, 'r', encoding='utf-8') as f:
draft_content = json.load(f)
# Extract tracks and segments information
tracks = []
if 'tracks' in draft_content:
for track_data in draft_content['tracks']:
track = {
'id': track_data.get('id', ''),
'name': track_data.get('name', f"Track {track_data.get('index', 0) + 1}"),
'type': track_data.get('type', 'video'),
'index': track_data.get('index', 0),
'segments': [],
'properties': track_data.get('properties', {})
}
# Extract segments
if 'segments' in track_data:
for segment_data in track_data['segments']:
segment = {
'id': segment_data.get('id', ''),
'type': segment_data.get('type', 'video'),
'name': segment_data.get('name', 'Unnamed Segment'),
'start_time': segment_data.get('start_time', 0),
'end_time': segment_data.get('end_time', 0),
'duration': segment_data.get('duration', 0),
'resource_path': segment_data.get('resource_path', ''),
'properties': segment_data.get('properties', {}),
'effects': segment_data.get('effects', [])
}
track['segments'].append(segment)
tracks.append(track)
# Build detailed template information
detail = {
'id': template.id,
'name': template.name,
'description': template.description,
'canvas_config': template.canvas_config,
'tracks': tracks,
'duration': template.duration,
'fps': draft_content.get('fps', 30),
'sample_rate': draft_content.get('sample_rate')
}
return detail
except Exception as e:
logger.error(f"Failed to get template detail for {template_id}: {e}")
return None
def main():
"""Command line interface for template management."""
@@ -474,6 +548,21 @@ def main():
else:
rpc.error(JSONRPCError.TEMPLATE_NOT_FOUND, "Failed to delete template")
elif args.action == "get_template_detail":
if not args.template_id:
rpc.error(JSONRPCError.INVALID_PARAMS, "Template ID is required")
return
detail = manager.get_template_detail(args.template_id)
if detail:
result = {
"status": True,
"detail": detail
}
rpc.success(result)
else:
rpc.error(JSONRPCError.TEMPLATE_NOT_FOUND, f"Template detail not found: {args.template_id}")
else:
rpc.error(JSONRPCError.METHOD_NOT_FOUND, f"Unknown action: {args.action}")