#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
检查视频文件中的字幕内容是否正确对应
"""

import os
import sqlite3
import re


def check_video_subtitle_match():
    """
    检查视频文件中的字幕内容是否正确对应
    """
    # 获取字幕数据
    db_path = r"\\ll\\d\\xtrssvjj\\dpd.db"
    conn = sqlite3.connect(db_path)
    cur = conn.cursor()
    
    cur.execute("SELECT idx, cn FROM srts WHERE adid=? ORDER BY idx", (8407,))
    srtsdata = cur.fetchall()
    conn.close()
    
    # 创建字幕字典
    subtitle_dict = {idx: cn for idx, cn in srtsdata}
    
    # 检查视频文件
    video_dir = "我们需要知识分子吗_思考_videos"
    video_files = []
    for filename in os.listdir(video_dir):
        if filename.endswith('.mp4') and filename.startswith('video_'):
            match = re.match(r'video_(\d+)\.mp4', filename)
            if match:
                idx = int(match.group(1))
                video_files.append((idx, filename))
    
    video_files.sort(key=lambda x: x[0])
    
    print("前10个视频文件及其对应的字幕:")
    for idx, filename in video_files[:10]:
        if idx in subtitle_dict:
            print(f"video_{idx:03d}.mp4: {subtitle_dict[idx]}")
        else:
            print(f"video_{idx:03d}.mp4: 无对应字幕")


if __name__ == "__main__":
    check_video_subtitle_match()
