import os
from utils.audio_analysis import audio_analysis_pipeline
from modules.video_processing.video_concat import merge_videos
from modules.video_processing.video_cut import video_cut_by_json

from utils.llm_director import director_json
from utils.video_concat import concat_videos
from utils.common import read_video_list, find_vidoe2cut


def main(video_path):

    # # 1、提取音频文件，用于语句筛选
    # audio_analysis_pipeline(video_path)

    # 2、获取语句筛选后的json文件
    video_name = os.path.splitext(os.path.basename(video_path))[0]
    json2script_path = f"output/filter_4/{video_name}.json"

    # # 3、口播脚本生成
    video_list = director_json(json2script_path)
    find_vidoe2cut(json2script_path, video_list)

    # 4、脚本视频片段裁切
    json2cut_path = f"output/for_cut/{video_name}.json"
    video_cut_by_json(json2cut_path)

    # 5、视频拼接
    video_list = read_video_list(f"output/script/{video_name}.json")
    video_list = [f"output/video_clips/{video_name}" for video_name in video_list]
    concat_videos(video_list)


    # 6、TODO：I 先生成脚本，再进行片段裁切；II 字幕纠偏和换行

    # 7、TODO: fisrt_cut \ oral_cut \\ aide_cut -> show_cut

    # 8、TODO: 口播片段筛选规则调整，确保至少筛留200个视频片段（关键词筛留规则）

main("data/sub_video/videoa.mp4")