File size: 2,739 Bytes
3b13b0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import json
from typing import Dict, Any

def check_format(script_content: str) -> Dict[str, Any]:
    """检查脚本格式
    Args:
        script_content: 脚本内容
    Returns:
        Dict: {'success': bool, 'message': str}
    """
    try:
        # 检查是否为有效的JSON
        data = json.loads(script_content)
        
        # 检查是否为列表
        if not isinstance(data, list):
            return {
                'success': False,
                'message': '脚本必须是JSON数组格式'
            }
        
        # 检查每个片段
        for i, clip in enumerate(data):
            # 检查必需字段
            required_fields = ['narration', 'picture', 'timestamp']
            for field in required_fields:
                if field not in clip:
                    return {
                        'success': False,
                        'message': f'第{i+1}个片段缺少必需字段: {field}'
                    }
            
            # 检查字段类型
            if not isinstance(clip['narration'], str):
                return {
                    'success': False,
                    'message': f'第{i+1}个片段的narration必须是字符串'
                }
            if not isinstance(clip['picture'], str):
                return {
                    'success': False,
                    'message': f'第{i+1}个片段的picture必须是字符串'
                }
            if not isinstance(clip['timestamp'], str):
                return {
                    'success': False,
                    'message': f'第{i+1}个片段的timestamp必须是字符串'
                }
            
            # 检查字段内容不能为空
            if not clip['narration'].strip():
                return {
                    'success': False,
                    'message': f'第{i+1}个片段的narration不能为空'
                }
            if not clip['picture'].strip():
                return {
                    'success': False,
                    'message': f'第{i+1}个片段的picture不能为空'
                }
            if not clip['timestamp'].strip():
                return {
                    'success': False,
                    'message': f'第{i+1}个片段的timestamp不能为空'
                }

        return {
            'success': True,
            'message': '脚本格式检查通过'
        }

    except json.JSONDecodeError as e:
        return {
            'success': False,
            'message': f'JSON格式错误: {str(e)}'
        }
    except Exception as e:
        return {
            'success': False,
            'message': f'检查过程中发生错误: {str(e)}'
        }