#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""武家坡 v2：把旧版 10 段提示词改写成「大学校道 · 林荫斑驳阳光 · 不要红包」。
做法：读旧 prompt_seg*.txt 的 detailed_description 动作段 → 逐条替换场景/背包措辞 → 套新 header + 新音效段。
输出：prompt_v2_seg1..10.txt（供 --seg-prompt 使用）
"""
from pathlib import Path
import re

BASE = Path('/home/zyw/Downloads/dl-hub/10-视频生成流水线/20261007_0450_H3换人_源15武家坡_新人物_含二采')
header = (BASE / 'prompt_header_v2_校道无包.txt').read_text(encoding='utf-8')

TAIL = """
overall_soundscape:
Campus ambience runs through the whole shot: leaves rustling in a light breeze overhead, sparrows and a distant cuckoo, a bicycle bell far off, faint chatter and footsteps from somewhere beyond the hedge, and the soft scuff of sneakers on the paved road.

non_diegetic_music:
A warm modern score at a flowing dance tempo: a soft string pad and plucked strings under a light electronic beat, with a simple melodic phrase that repeats and grows slightly through the take.
"""

# 场景替换（长串优先，避免误伤）
REPL = [
    # 背包：整句删除或改写（必须先处理带 bag 的长句）
    (" and her left arm relaxed beside the red shoulder bag", " and her left arm relaxed at her side"),
    (" while the pleated skirt flares and the bag swings forward on its strap", " while the pleated skirt flares out around her thighs"),
    (" while the pleated skirt drops over her thighs and the bag slides forward against her ribs", " while the pleated skirt drops over her thighs"),
    (" the skirt swinging with each step and the bag bumping against her hip", " the skirt swinging with each step"),
    (" the pleated skirt flicking out and the red bag swinging on its long strap", " the pleated skirt flicking out around her legs"),
    (" the pleated skirt presses against the front of her thighs and the bag slides around her hip", " the pleated skirt presses against the front of her thighs"),
    (" the pleated skirt hanging in clean pleats and the bag swinging out on its strap", " the pleated skirt hanging in clean pleats"),
    (" the skirt hanging in clean pleats and the bag swinging out on its strap", " the skirt hanging in clean pleats"),
    (" and lets her weight settle onto one leg so that the pleated skirt swings across her thighs and the bag slips to the front of her hip",
     " and lets her weight settle onto one leg so that the pleated skirt swings across her thighs"),
    (" the pleated skirt shifting with the lean and the red bag resting against her hip", " the pleated skirt shifting with the lean"),
    (" the pleated skirt falls still around her thighs and the red bag hangs quietly at her hip", " the pleated skirt falls still around her thighs"),
    (" the skirt swinging in time, the bag knocking lightly against her side", " the skirt swinging in time"),
    (" and the bag hanging at her hip", ""),
    ("the red shoulder bag", "her side"),
    ("the red bag", "the skirt"),
    ("the bag", "the skirt"),
    # 舞台 → 校道
    ("on the stage of <Subject 3>", "on the tree-lined campus road of <Subject 3>"),
    ("on the boards", "on the paved road"),
    ("polished boards", "paved road surface"),
    ("the boards", "the road"),
    ("polished wood", "paved road surface"),
    ("wooden stage floor", "paved campus road"),
    ("the stage of <Subject 3>", "the campus road of <Subject 3>"),
    ("stage of <Subject 3>", "campus road of <Subject 3>"),
    ("the boards of <Subject 3>", "the road of <Subject 3>"),
    # 灯光/幕布 → 林荫斑驳阳光
    ("the crimson curtain behind her stays softly out of focus throughout", "the leafy canopy overhead stays softly out of focus throughout"),
    ("the crimson curtain and black masking stay softly out of focus behind her", "the leafy canopy and the distant teaching building stay softly out of focus behind her"),
    ("the crimson curtain hangs still behind her", "the leafy canopy hangs still behind her"),
    ("the crimson curtain glows softly behind her", "the green canopy glows softly overhead"),
    ("the haze in the beam softens the crimson curtain behind her", "the sunlit leaves soften the far end of the avenue behind her"),
    ("warm spotlight beams from above catch the haze around her", "bright patches of sunlight come down through the leaves around her"),
    ("haze drifts through the beams above her", "the leaves stir overhead and the light patches drift across the road"),
    ("haze drifts slowly through the beams", "the light patches drift slowly across the road"),
    ("haze drifts through the light beams above her", "the leaves stir overhead and the light patches shift"),
    ("Warm spotlights from above carve bright pools on the boards around her sneakers, cool light edges her shoulders, faint haze glows in the beams",
     "Dappled sunlight lays bright moving patches on the pavement around her sneakers, green shade cools her shoulders, and the light keeps shifting through the leaves"),
    ("Warm light rakes across her left side and cool light fills her right", "Dappled sunlight crosses her from the left while cool green shade fills her right"),
    ("Warm downlight glows along her arms, the polished boards reflect a soft sheen under her feet",
     "Warm sunlight glows along her arms, and the paved road holds a soft sheen under her feet"),
    ("Warm light catches the top of her head and shoulders", "Warm sunlight catches the top of her head and shoulders"),
    ("Warm light catches the moving pleats", "Sunlight catches the moving pleats"),
    ("Warm key light falls on her face", "Dappled sunlight falls across her face"),
    ("Warm stage light picks out the edge of her raised arm and the moving pleats of the skirt",
     "Sunlight picks out the edge of her raised arm and the moving pleats of the skirt"),
    ("Warm and cool stage lights cross on her from both sides, haze drifts slowly through the beams",
     "Dappled sunlight flickers across her from the left, cool green shade on her right, and the light patches keep moving on the road"),
    ("Warm spotlights pool around her feet", "Bright sunlight pools around her feet"),
    ("a quiet, distant auditorium beyond the front edge of the stage", "a quiet campus beyond the hedge"),
    ("Stage sound runs through the whole shot", "Campus ambience runs through the whole shot"),
    # 二轮补丁（残留舞台/聚光灯措辞 + 替换副作用）
    ("across the stage", "across the road"),
    ("Warm spotlights from above carve bright pools on the paved road around her sneakers, cool light edges her shoulders, faint haze glows in the beams",
     "Dappled sunlight comes down through the leaves in bright patches on the paved road around her sneakers, and green shade cools her shoulders"),
    ("Warm and cool stage lights cross on her from both sides", "Dappled sunlight crosses her from the left and cool green shade from the right"),
    ("Her sneakers pivot softly on the wood", "Her sneakers pivot softly on the pavement"),
    ("warm spotlights pool around her feet", "bright sunlight pools around her feet"),
    (", the skirt knocking lightly against her side", ""),
]

acts = []
for i in range(1, 11):
    old = (BASE / f'prompt_seg{i}.txt').read_text(encoding='utf-8')
    m = re.search(r'(?ms)^(At 0\.00 seconds .*?)(?=^overall_soundscape:)', old)
    act = m.group(1).rstrip()
    for a, b in REPL:
        act = act.replace(a, b)
    acts.append(act)
    (BASE / f'prompt_v2_seg{i}.txt').write_text(header + act + '\n' + TAIL, encoding='utf-8')

print('wrote prompt_v2_seg1..10.txt')
for i, a in enumerate(acts, 1):
    bad = [w for w in ('bag', 'stage', 'spotlight', 'crimson', 'boards', 'polished wood') if w in a.lower()]
    if bad:
        print(f'  ⚠ 段{i} 仍有残留词: {bad}')
