
    }j                         d dl Zd dlmc mZ d dlmZ d dlZd dl	m
Z
mZmZmZ d dlmZmZ d Zd Zd Zd Zd	 Zd
 ZdS )    N)Path)AudioCaptionPreviewPlan build_audio_caption_preview_planrender_audio_caption_preview#validate_audio_caption_preview_plan)!build_final_motion_subtitle_trackbuild_hormozi_subtitle_trackc                    | dz  }| dz  }t          dd          }t          |||| dz            }|j        }t          |          }||k    }|s0t	          j        d|fd	||f          d
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          dt          j                    v st	          j        t                    rt	          j	        t                    nddt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          dz  }dd|iz  }	t          t	          j        |	                    d x}x}}|j        }t          |          }||k    }|s0t	          j        d|fd||f          d
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          dt          j                    v st	          j        t                    rt	          j	        t                    nddt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          dz  }dd|iz  }	t          t	          j        |	                    d x}x}}|j        }|j        }d}
 ||
          }|sdd
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          t	          j	        |          t	          j	        |
          t	          j	        |          dz  }t          t	          j        |                    d x}x}x}
}|j        }|j        }d}
 ||
          }|sdd
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          t	          j	        |          t	          j	        |
          t	          j	        |          dz  }t          t	          j        |                    d x}x}x}
}|j        }d}||k    }|st	          j        d|fd||f          d
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          t	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}d}|j        }||v }|st	          j        d|fd||f          t	          j	        |          d
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}d}|j        }||v }|st	          j        d|fd||f          t	          j	        |          d
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}d }|j        }||v }|st	          j        d|fd||f          t	          j	        |          d
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}|j        }d!}||k    }|st	          j        d|fd"||f          d
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          t	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}|j        }d!}||k    }|st	          j        d|fd#||f          d
t          j                    v st	          j        |          rt	          j	        |          nd
t	          j	        |          t	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}d S )$N
timing.mp4	voice.mp3z>Most AI automations quietly rot when workflows lack boundaries   total_duration_secondsfinal-preview.mp4
video_path
audio_pathsubtitle_trackoutput_path==)zP%(py2)s
{%(py2)s = %(py0)s.video_path
} == %(py7)s
{%(py7)s = %(py4)s(%(py5)s)
}planstrr   py0py2py4py5py7assert %(py9)spy9)zP%(py2)s
{%(py2)s = %(py0)s.audio_path
} == %(py7)s
{%(py7)s = %(py4)s(%(py5)s)
}r   zkassert %(py8)s
{%(py8)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.output_path
}.endswith
}(%(py6)s)
})r   r   r   py6py8zfinal-preview.asszrassert %(py8)s
{%(py8)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.subtitle_file_path
}.endswith
}(%(py6)s)
}preserve_videoz5%(py2)s
{%(py2)s = %(py0)s.duration_mode
} == %(py5)sr   r   r   assert %(py7)sr   z[Script Info]inz=%(py1)s in %(py5)s
{%(py5)s = %(py3)s.subtitle_file_content
}py1py3r   z	Dialogue:zMOST AI AUTOMATIONS z4%(py2)s
{%(py2)s = %(py0)s.side_effects
} == %(py5)sz6%(py2)s
{%(py2)s = %(py0)s.external_calls
} == %(py5)s)r	   r   r   r   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationr   r   endswithsubtitle_file_pathduration_modesubtitle_file_contentside_effectsexternal_calls)tmp_pathr   r   trackr   @py_assert1@py_assert6@py_assert3@py_format8@py_format10@py_assert5@py_assert7@py_format9@py_assert4@py_format6@py_assert0@py_assert2s                    Z/home/agent/jarvis_runtime/autoshortsbot/AutoShortsBot/tests/test_audio_caption_preview.pyPtest_build_audio_caption_preview_plan_is_side_effect_free_and_writes_ass_contentrN      s0
   L(JK'J()i  CD  E  E  EE+22	  D ?-c*oo-?o----------?o------------4-----4------?-----------c-----c-------------*-----*------o---------------------------?-c*oo-?o----------?o------------4-----4------?-----------c-----c-------------*-----*------o---------------------------9$9%89$$%899999999999999949999949999999999$9999%89999999999999999999999999999"@"+@,?@++,?@@@@@@@@@@@@@@@4@@@@@4@@@@@@"@@@@+@@@@,?@@@@@@@@@@@@@@@@@@@@@@@@@@@@1!11!11111111111!111111111111141111141111111111!11111111111111111111111111118d88?88888888888?888888?88888888888d88888d88888888888888888888888888888888884$44;44444444444;444444;44444444444$44444$4444444444444444444444444444444444 >D$>> $>>>>>>>>>>> $>>>>>> >>>>>>>>>>>D>>>>>D>>>>>>$>>>>>>>>>>>>>>>>>>>>>>>>>>>>""""""""""""""""""""""""4"""""4"""""""""""""""""""""""""""""""""""""$"$"$$$$$$$$$$"$$$$$$$$$$$$4$$$$$4$$$$$$$$$$"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    c                     t          dd          } t          dd| d          }| j        }|j        }d}||k    }|st	          j        d	|fd
||f          dt          j                    v st	          j        |           rt	          j	        |           ndt	          j	        |          t	          j	        |          t	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}x}x}}d | j        D             }t          |          }|sddt          j                    v st	          j        t                    rt	          j	        t                    ndt	          j	        |          t	          j	        |          dz  }t          t	          j        |                    d x}}d}	|j        }
|	|
v}|st	          j        d|fd|	|
f          t	          j	        |	          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |
          dz  }dd|iz  }t          t	          j        |                    d x}	x}}
d}	|j        }
|	|
v }|st	          j        d|fd|	|
f          t	          j	        |	          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |
          dz  }dd|iz  }t          t	          j        |                    d x}	x}}
d}	|j        }
|	|
v }|st	          j        d|fd|	|
f          t	          j	        |	          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |
          dz  }dd|iz  }t          t	          j        |                    d x}	x}}
d S )NzyBefore you automate anything, decide three things: what should go through, what should be reviewed, and what should stop.   r   r   r   r   r   truetrace_final_motion_compactr   )zG%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.style
}.name
} == %(py7)sr@   )r   r   r   r   r    r!   c              3   ~   K   | ]8}d t          |j                                                  cxk    odk    nc V  9dS )      N)lentextsplit).0cues     rM   	<genexpr>zPtest_render_ass_subtitle_file_uses_compact_final_motion_style.<locals>.<genexpr>2   sR      EE3qC(())....Q....EEEEEErO   z,assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}allr   r   r   zANYTHING DECIDE THREEnot in)zA%(py1)s not in %(py5)s
{%(py5)s = %(py3)s.subtitle_file_content
}r   r+   r'   r   z!Style: TrueTraceCaption,Arial,72,r(   r*   z,80,80,320,1)r   r   stylenamer1   r2   r3   r4   r5   r6   r7   r8   cuesr\   r<   )r@   r   rA   rC   rB   rF   rD   rE   @py_format5rK   rI   rL   rJ   s                rM   =test_render_ass_subtitle_file_uses_compact_final_motion_stylerd   %   s   - 	D   E ,'	  D ;?;???????????????????????????5?????5??????;??????????????????????????????????????EE%*EEEE3EEEEEEEEEEEEEEEE3EEEEE3EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"D$*DD"*DDDDDDDDDDD"*DDDDDD"DDDDDDDDDDD$DDDDD$DDDDDD*DDDDDDDDDDDDDDDDDDDDDDDDDDDD.L$2LL.2LLLLLLLLLLL.2LLLLLL.LLLLLLLLLLL$LLLLL$LLLLLL2LLLLLLLLLLLLLLLLLLLLLLLLLLLL7T77>77777777777>777777>77777777777T77777T777777777777777777777777777777777777rO   c                 
   t          dd          }t          ddddd|d	d
d	  	        }t          |          }|j        }d}||u }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}d}	|j        }|	|v }
|
st	          j        d|
fd|	|f          t	          j	        |	          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}	x}
}d}	|j        }|	|v }
|
st	          j        d|
fd|	|f          t	          j	        |	          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}	x}
}d}	|j        }|	|v }
|
st	          j        d|
fd|	|f          t	          j	        |	          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}	x}
}d}	|j        }|	|v }
|
st	          j        d|
fd|	|f          t	          j	        |	          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}	x}
}d}	|j        }|	|v }
|
st	          j        d|
fd|	|f          t	          j	        |	          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}	x}
}d}	|j        }|	|v }
|
st	          j        d|
fd|	|f          t	          j	        |	          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          dz  }dd|iz  }t          t	          j        |                    d x}	x}
}d S )Nzvalid subtitle text   r   z	video.movz	voice.wavzout.avizout.srt shortest)
write_fileffmpeg)	r   r   r   r:   r<   r   r;   r=   r>   F)is)z0%(py2)s
{%(py2)s = %(py0)s.is_valid
} is %(py5)s
validationr&   r'   r   zvideo_path must end with .mp4r(   )z.%(py1)s in %(py5)s
{%(py5)s = %(py3)s.errors
}r+   zaudio_path must end with .mp3zoutput_path must end with .mp4z%subtitle_file_path must end with .assz5duration_mode must be preserve_video or trim_to_audioz6audio caption preview plans must not have side effects)r	   r   r   is_validr1   r2   r3   r4   r5   r6   r7   r8   errors)r?   r@   r   rm   rA   rI   rC   rJ   rD   rK   rL   s              rM   Rtest_validate_audio_caption_preview_plan_rejects_bad_paths_and_unsafe_side_effectsrp   8   s   ()>WXYYYE"$  $"
 
 
D 5T::J'%'%''''''''''%'''''''''''':''''':''''''''''%'''''''''''''''''''''''''''*?j.??*.???????????*.??????*???????????j?????j??????.????????????????????????????*?j.??*.???????????*.??????*???????????j?????j??????.????????????????????????????+@z/@@+/@@@@@@@@@@@+/@@@@@@+@@@@@@@@@@@z@@@@@z@@@@@@/@@@@@@@@@@@@@@@@@@@@@@@@@@@@2Gj6GG26GGGGGGGGGGG26GGGGGG2GGGGGGGGGGGjGGGGGjGGGGGG6GGGGGGGGGGGGGGGGGGGGGGGGGGGGBWjFWWBFWWWWWWWWWWWBFWWWWWWBWWWWWWWWWWWjWWWWWjWWWWWWFWWWWWWWWWWWWWWWWWWWWWWWWWWWWCXzGXXCGXXXXXXXXXXXCGXXXXXXCXXXXXXXXXXXzXXXXXzXXXXXXGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXrO   c                    t          dd          }t          | dz  | dz  || dz  d          }|j        }d}||k    }|st          j        d	|fd
||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}}|j        }d}||k    }|st          j        d	|fd||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}}|j        }d}||k    }|st          j        d	|fd||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j
        |                    d x}x}}d S )N/Prompt is not system workflow boundaries matterrU   r   r   r   	final.mp4trim_to_audior   r   r   r   r;   r   r%   r   r&   r'   r   r.   r/   r0   )r	   r   r;   r1   r2   r3   r4   r5   r6   r7   r8   r=   r>   )r?   r@   r   rA   rI   rC   rJ   rD   s           rM   Btest_build_audio_caption_preview_plan_can_explicitly_trim_to_audiorv   Q   s   ()ZstuuuE+l*k){*%  D 00000000000000000000000040000040000000000000000000000000000000000000""""""""""""""""""""""""4"""""4"""""""""""""""""""""""""""""""""""""$"$"$$$$$$$$$$"$$$$$$$$$$$$4$$$$$4$$$$$$$$$$"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$rO   c           	         | dz  }| dz  }| dz  |                     d           |                     d           t          dd          }t          |||	          }g fd
}t          ||          }|j        }t          |          }|j        }	 |	            }
|
sddt          j                    v st          j
        t
                    rt          j        t
                    nddt          j                    v st          j
        |          rt          j        |          ndt          j        |          t          j        |          t          j        |	          t          j        |
          dz  }t          t          j        |                    d x}x}x}	}
j        } |            }|sddt          j                    v st          j
                  rt          j                  ndt          j        |          t          j        |          dz  }t          t          j        |                    d x}}d         d d         }dddt          |          dg}||k    }|slt          j        d|fd||f          t          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}}d}d}|j        }d         } ||          }||v }|st          j        d|fd ||f          t          j        |          t          j        |          t          j        |          t          j        |          t          j        |          d!z  }d"d#|iz  }t          t          j        |                    d x}x}x}x}x}}d$}d         }||v}|slt          j        d%|fd&||f          t          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}}|j        }t                    }	||	k    }|s0t          j        d|fd'||	f          d(t          j                    v st          j
        |          rt          j        |          nd(t          j        |          d)t          j                    v st          j
        t                    rt          j        t                    nd)dt          j                    v st          j
                  rt          j                  ndt          j        |	          d*z  }d+d,|iz  }t          t          j        |                    d x}x}}	|j        }d-}||k    }|st          j        d|fd.||f          d(t          j                    v st          j
        |          rt          j        |          nd(t          j        |          t          j        |          d/z  }d0d1|iz  }t          t          j        |                    d x}x}}|j        }d2}||k    }|st          j        d|fd3||f          d(t          j                    v st          j
        |          rt          j        |          nd(t          j        |          t          j        |          d/z  }d0d1|iz  }t          t          j        |                    d x}x}}|j        }d4}||k    }|st          j        d|fd5||f          d(t          j                    v st          j
        |          rt          j        |          nd(t          j        |          t          j        |          d/z  }d0d1|iz  }t          t          j        |                    d x}x}}d S )6Nr   r   rs   
   fake video
   fake audiorr   rU   r   r   c                                         |                                d           t          j        | ddd          S Ns   fake final videor   okrg   )stdoutstderrappendwrite_bytes
subprocessCompletedProcesscommandcapture_outputrW   checkcallsoutputs       rM   fake_runnerzZtest_render_audio_caption_preview_preserves_video_duration_by_default.<locals>.fake_runnerp   D    W.///*7Ad2NNNNrO   runnerzassert %(py9)s
{%(py9)s = %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.subtitle_file_path
})
}.exists
}()
}r   r   )r   r,   r-   r   r   r!   zAassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}r   r]   r   r   rk   z-yz-ir   )z%(py1)s == %(py4)sr,   r   assert %(py6)sr"   zass= r(   )zL%(py1)s in %(py10)s
{%(py10)s = %(py6)s
{%(py6)s = %(py4)s.join
}(%(py8)s)
})r,   r   r"   r#   py10zassert %(py12)spy12	-shortestr^   )z%(py1)s not in %(py4)s)zQ%(py2)s
{%(py2)s = %(py0)s.output_path
} == %(py7)s
{%(py7)s = %(py4)s(%(py5)s)
}resultr   r   r    r!   r$   r%   r&   r'   r   )write_subtitlescall_ffmpeg	write_mp4r/   rj   r0   )r   r	   r   r   r:   r   existsr3   r4   r1   r5   r6   r7   r8   r   r2   joinr   r;   r=   r>   )r?   input_videoaudior@   r   r   r   rL   rI   rB   @py_assert8rE   rA   rC   rc   rK   @py_format7rF   rG   @py_assert9@py_format11@py_format13rD   rJ   r   r   s                           @@rM   Etest_render_audio_caption_preview_preserves_video_duration_by_defaultr   a   s   \)K{"E#FM***	m$$$()ZstuuuE+	  D EO O O O O O
 *${CCCF'14'((1(/1//1111111111111114111114111111111111111111111111'1111(1111/1111111111111111111111111111===???66=?8BQB<IHdD#k2B2BDII<IIIIIIIIIII<IIIIII<IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII'S'SX'eAh'XXh'''6'''''''''''6''''''6''''S''''X''''h''''''''''''''''''''''''''''''''''''''&eAh&;h&&&&&&&&&&;h&&&&&;&&&&h&&&&&&&&&&&&&&&&&&&&&&&&&&&,V,,,,,,,,,,,,,,,,,,,,,,,6,,,,,6,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,V,,,,,V,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3#33#33333333333#333333333333363333363333333333#3333333333333333333333333333Q"QQ"QQQQQQQQQQQ"QQQQQQQQQQQQQ6QQQQQ6QQQQQQQQQQ"QQQQQQQQQQQQQQQQQQQQQQQQQQQQ /K/ K////////// K////////////6/////6////// ////K/////////////////////////////rO   c                 ~   | dz  }| dz  }| dz  |                     d           |                     d           t          dd          }t          |||d	
          }g fd}t          ||          }d}d         }||v }	|	slt	          j        d|	fd||f          t	          j        |          t	          j        |          dz  }
dd|
iz  }t          t	          j        |                    d x}x}	}|j	        }d	}||k    }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j        |          ndt	          j        |          t	          j        |          dz  }dd|iz  }t          t	          j        |                    d x}x}}d S )Nr   r   rs   rx   ry   rr   rU   r   rt   ru   c                                         |                                d           t          j        | ddd          S r{   r   r   s       rM   r   zOtest_render_audio_caption_preview_trims_only_when_explicit.<locals>.fake_runner   r   rO   r   r   r   r(   )z%(py1)s in %(py4)sr   r   r"   r   r%   r   r&   r'   r   )r   r	   r   r   r1   r2   r6   r7   r8   r;   r3   r4   r5   )r?   r   r   r@   r   r   r   rK   rC   rL   rc   r   rA   rI   rJ   rD   r   r   s                   @@rM   :test_render_audio_caption_preview_trims_only_when_explicitr      sL   \)K{"E#FM***	m$$$()ZstuuuE+%  D EO O O O O O
 *${CCCF"%(";("""""""""";(""""";""""("""""""""""""""""""""""""""2?2?2222222222?22222222222262222262222222222?22222222222222222222222222222rO   )builtinsr3   _pytest.assertion.rewrite	assertionrewriter1   pathlibr   r   autoshorts.audio.final_previewr   r   r   r   autoshorts.audio.subtitlesr   r	   rN   rd   rp   rv   r   r   r.   rO   rM   <module>r      s                                       g f f f f f f f% % %08 8 8&Y Y Y2% % % 0 0 0B3 3 3 3 3rO   