diff --git a/python_core/services/template_manager.py b/python_core/services/template_manager.py index 5c40311..b078a6d 100644 --- a/python_core/services/template_manager.py +++ b/python_core/services/template_manager.py @@ -393,6 +393,31 @@ class TemplateManager: with open(draft_content_path, 'r', encoding='utf-8') as f: draft_content = json.load(f) + # Build material lookup tables + materials_lookup = {} + if 'materials' in draft_content: + # Index videos by id + for video in draft_content['materials'].get('videos', []): + video_id = video.get('id', '') + if video_id: + materials_lookup[video_id] = { + 'type': 'video', + 'path': video.get('path', ''), + 'name': video.get('material_name', ''), + 'duration': video.get('duration', 0) + } + + # Index audios by id + for audio in draft_content['materials'].get('audios', []): + audio_id = audio.get('id', '') + if audio_id: + materials_lookup[audio_id] = { + 'type': 'audio', + 'path': audio.get('path', ''), + 'name': audio.get('name', ''), + 'duration': audio.get('duration', 0) + } + # Extract tracks and segments information tracks = [] if 'tracks' in draft_content: @@ -421,19 +446,36 @@ class TemplateManager: # Get material reference for resource path material_id = segment_data.get('material_id', '') + # 参考assets/draft_content.json 根据material_id匹配materials中的videos resource_path = '' - if material_id: - # TODO: Look up material path from materials list - resource_path = f"material_{material_id}" + material_name = '' + segment_type = segment_data.get('type', 'video') + + if material_id and material_id in materials_lookup: + material_info = materials_lookup[material_id] + resource_path = material_info['path'] + material_name = material_info['name'] + # Auto-detect segment type from material type if not specified + if not segment_data.get('type'): + segment_type = material_info['type'] + + # Generate segment name based on material name or default + segment_name = segment_data.get('name', '') + if not segment_name: + if material_name: + segment_name = material_name + else: + segment_name = f'片段 {len(track["segments"]) + 1}' segment = { 'id': segment_data.get('id', ''), - 'type': segment_data.get('type', 'video'), - 'name': segment_data.get('name', f'随机'), + 'type': segment_type, + 'name': segment_name, 'start_time': start_time, 'end_time': end_time, 'duration': duration, 'resource_path': resource_path, + 'material_name': material_name, 'properties': segment_data.get('properties', {}), 'effects': segment_data.get('effects', []) } diff --git a/src/components/timeline/SegmentContextMenu.tsx b/src/components/timeline/SegmentContextMenu.tsx index 10e4b6f..6032b5e 100644 --- a/src/components/timeline/SegmentContextMenu.tsx +++ b/src/components/timeline/SegmentContextMenu.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { Edit, Copy, Trash2, Info } from 'lucide-react' +import { Edit } from 'lucide-react' interface SegmentContextMenuProps { isOpen: boolean @@ -15,10 +15,7 @@ export const SegmentContextMenu: React.FC = ({ isOpen, position, onClose, - onEdit, - onCopy, - onDelete, - onInfo + onEdit }) => { React.useEffect(() => { if (isOpen) { @@ -58,48 +55,6 @@ export const SegmentContextMenu: React.FC = ({ 重命名 - - {onCopy && ( - - )} - - {onInfo && ( - - )} - - {onDelete && ( - <> -
- - - )} ) } diff --git a/src/components/timeline/TrackTimeline.tsx b/src/components/timeline/TrackTimeline.tsx index 4a1937b..09527a2 100644 --- a/src/components/timeline/TrackTimeline.tsx +++ b/src/components/timeline/TrackTimeline.tsx @@ -191,7 +191,7 @@ export const TrackTimeline: React.FC = ({ key={segment.id} className={`absolute top-2 bottom-2 rounded-md ${getSegmentColor(segment.type)} ${getSegmentTextColor(segment.type)} flex items-center px-3 text-sm font-medium cursor-pointer transition-all duration-200 - shadow-sm hover:shadow-md transform hover:scale-105 z-10`} + shadow-sm hover:shadow-md transform`} style={{ left: `${startPercent}%`, width: `${Math.max(widthPercent, 8)}%`, // Minimum width for visibility