#!/usr/bin/env python3
"""
计算"金身不好玩"音频文件长度加上所有字幕ttsdur的总时长
"""
import sqlite3
import subprocess

db_path = "\\\\ll\\D\\xtrssvjj\\dpd.db"
audio_file = "\\\\ll\\d\\xtrssvjj\\金身不好玩.mp3"

# 获取音频文件长度
print("获取音频文件长度...")
cmd = ["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", audio_file]
result = subprocess.run(cmd, capture_output=True, text=True)
total_duration = float(result.stdout.strip())
print(f"音频文件长度: {total_duration:.2f}秒")

# 查询所有字幕的ttsdur并累加
conn = sqlite3.connect(db_path)
cursor = conn.cursor()

adid = 8370
cursor.execute("SELECT ttsdur FROM srts WHERE adid = ?", (adid,))
ttsdur_list = cursor.fetchall()

conn.close()

if ttsdur_list:
    total_ttsdur = sum([item[0] for item in ttsdur_list if item[0]])
    total_ttsdur_seconds = total_ttsdur / 1000  # 转换为秒
    print(f"所有字幕ttsdur累加: {total_ttsdur}毫秒 ({total_ttsdur_seconds:.2f}秒)")
    
    total_total = total_duration + total_ttsdur_seconds
    print(f"总时长: {total_total:.2f}秒 ({total_total/60:.2f}分钟)")
else:
    print("未找到字幕记录")
