#!/usr/bin/env python3
"""
检查拼接列表内容
"""
import os

# 导入编码处理模块
from console_helper import (
    safe_print, print_header, print_step, print_info,
    print_success, print_fail, print_done
)


def main():
    # 配置
    output_video = "first_5_lines_check.mp4"
    max_lines = 5
    
    print_header("检查拼接列表")
    safe_print(f"输出视频: {output_video}")
    safe_print("")
    
    # 构建视频列表
    video_list = []
    
    print_step(1, 2, "构建视频列表...")
    for i in range(1, max_lines + 1):
        segment_file = f"all_segments/segment_{i:03d}.mp4"
        static_video_file = f"all_static_videos_with_silence/static_video_{i:03d}.mp4"
        
        # 检查文件是否存在
        if not os.path.exists(segment_file):
            safe_print(f"      警告: 原始片段文件 {segment_file} 不存在")
            continue
        
        if not os.path.exists(static_video_file):
            safe_print(f"      警告: 静态视频文件 {static_video_file} 不存在")
            continue
        
        # 添加到视频列表
        video_list.append(segment_file)
        video_list.append(static_video_file)
        
        print_info(f"  添加第{i}句", f"{os.path.basename(segment_file)} + {os.path.basename(static_video_file)}")
    
    if not video_list:
        safe_print("错误: 没有找到任何视频文件")
        return
    
    print_info("总视频数", str(len(video_list)))
    safe_print("")
    
    # 写入拼接列表文件（不删除）
    print_step(2, 2, "写入拼接列表...")
    list_file = 'concat_list_check.txt'
    with open(list_file, 'w', encoding='utf-8') as f:
        for video in video_list:
            escaped_path = video.replace('\\', '/')
            f.write(f"file '{escaped_path}'\n")
            safe_print(f"  写入: file '{escaped_path}'")
    
    print_info("列表文件", list_file)
    
    # 读取并显示文件内容
    safe_print("")
    safe_print("文件内容:")
    with open(list_file, 'r', encoding='utf-8') as f:
        content = f.read()
        safe_print(content)
    
    print_done()


if __name__ == '__main__':
    main()
