
    _j$                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ  ed          ZdZ	dZ
dZd"dZd#dZd$d%dZd&dZd'dZd(dZd#dZd#dZd#dZd#d Zed!k    r e             dS dS ))    )annotationsN)PathzR/data/video-pipeline/HaTramAudio/project/022-Tiem-Giat-Mo-Cua-Luc-Bon-Gio-Muoi-Bayz)022-Tiem-Giat-Mo-Cua-Luc-Bon-Gio-Muoi-Bayzrun-20260721T172022Z-9462493aLevypathr   returnstrc                   t          j                    }|                     d          5 t          fdd          D ]}|                    |           	 d d d            n# 1 swxY w Y   |                                S )Nrbc                 .                          d          S )Ni   )read)fs   work/build_render_request.py<lambda>zsha.<locals>.<lambda>   s    !&&"9"9     r   )hashlibsha256openiterupdate	hexdigest)r   hblockr   s      @r   shar      s    A	4 A99993?? 	 	EHHUOOOO	               ;;==s   ,A##A'*A'Nonec                    t          j        t          dz                      d                    } t          t
          t          d                                D ]0\  }}|                     |          |k    rt          d|           1d S )Nz.ownership-lock.jsonutf-8encoding)
project_idrun_idownerzownership mismatch: )
jsonloadsROOT	read_text
PROJECT_IDRUN_IDOWNERitemsgetRuntimeError)lockkeyvalues      r   guardr/      s    :t44???QQRRD%/6ERRXXZZ = =
U88C==E!!;c;;<<< "= =r   	completedallowed_statusestuple[str, ...]dictc                ~   t          j        |                     d                    }|                    dt                    t          k    s|                    d          t
          k    rt          d|            |                    d          |vs|                    d          durt          d	|            |S )
Nr   r   r   r    zreceipt identity mismatch: statusverifiedTzreceipt not terminal/verified: )r"   r#   r%   r*   r&   r'   r+   )r   r2   datas      r   read_verifiedr9      s    :dnngn6677Dxxj))Z77488H;M;MQW;W;W???@@@xx!111TXXj5I5IQU5U5UCTCCDDDKr   expectedlabelc                x    |                                  rt          |           |k    rt          | d          d S )Nz artifact hash mismatch)is_filer   r+   )r   r:   r;   s      r   ensure_hashr>   (   sA    <<>> >SYY(22e<<<=== 32r   tuple[dict, dict]c                d   t          j        dddddddt          |           g          }t          j        |                              dg           }d	 |D             }d
 |D             }t          |          dk    st          |          dk    rt          d|            |d         |d         fS )Nffprobez-verrorz-show_entrieszestream=codec_name,profile,codec_type,width,height,pix_fmt,r_frame_rate,time_base,sample_rate,channelsz-ofr"   streamsc                D    g | ]}|                     d           dk    |S )
codec_typevideor*   .0items     r   
<listcomp>z$stream_signature.<locals>.<listcomp>4   .    LLLt$((<*@*@G*K*Kd*K*K*Kr   c                D    g | ]}|                     d           dk    |S )rE   audiorG   rH   s     r   rK   z$stream_signature.<locals>.<listcomp>5   rL   r      z)expected one video and one audio stream: r   )
subprocesscheck_outputr   r"   r#   r*   lenr+   )r   rawrC   videosaudioss        r   stream_signaturerV   -   s    

!4/ovs4yy#  C
 joo!!)R00GLLwLLLFLLwLLLF
6{{a3v;;!++MtMMNNN!9fQir   stagepayloadbindingsc                   t                       t          dz  | z  t          z  }|                    dd           |dz  }|dz  }|                    t          j        |dd          d	z   d
           t          |          |d<   |                    t          j        |dd          d	z   d
           t          t          j        | t          |          |d         dd                     d S )NworkT)parentsexist_okzrequest.jsonzrequest-bindings.jsonF   )ensure_asciiindent
r   r   request_sha256)rW   requestrb   )r_   )
r/   r$   r'   mkdir
write_textr"   dumpsr   printr   )rW   rX   rY   r[   request_pathbinding_paths         r   write_requestrj   ;   s   	GGG&=5 6)DJJtdJ+++.(L11LDJwU1MMMPTT_fggg!$\!2!2HDJxeANNNQUU`ghhh	$*u\1B1BV^_oVpqq  AF  G  G  G  H  H  H  H  Hr   c                 \   t          t          dz  dz            } t          t          dz  dz            }t          t          dz  dz  d          }|                    d          p|                    d          }|                     d          |k    s|                    d          |k    rt          d	          t          d
z  dz  }t          dz  dz  dz  }t	          || d         d           t	          ||d         d           i dt          |          ddddddd
t          |          dt          t          dz  dz  dz            dddddd d!d"d#d$d%d&d'd(d)d*d+d"d,d-d.d/d0d1i}t          d|t          t          || d         |d         dd2dd|d         d3
           d S )4Nscriptztts-manifest.jsonimagezlayout-manifest.jsonzpromotion-report.json)passedr1   completed_content_onlycanon_sha256source_canon_sha256zfootage upstream canon mismatchrN   zstory-full.wav
normalizedzlayout-1920x1080.pngoutput_sha256TTSlayout_sha256layoutfootage_dirz(/data/video-pipeline/GacMaiAudio/footagepatternz*.mp4	recursiveToutputfootagefootage.mp4seedi5hx	overwriteFwidth  height8  fps   center_xi  center_yr   center_widthi`  center_heightvideo_encoder
h264_nvencpresetp4cq   hflip)
r   r    rq   source_audio_sha256source_layout_sha256mirror_requiredexpected_horizontal_transformsource_audio_must_be_discarded'production_narration_must_be_only_audiorz   )	r9   r$   r*   r+   r>   r   rj   r&   r'   )ttsrv   	promotion
canon_hashrN   layout_pathrX   s          r   r{   r{   G   s[   
x*==
>
>C4'>,BBCCFdXo0GGIz{{I~..V)--@U2V2VJ
ww$%%33vzzBW7X7X\f7f7f<===7N--E.</2HHKs?+U333VO4h???#k""A 	7 	T	
 	U 	#dXo	1MABB 	
 	U 	 	$ 	r 	C 	A 	 	  	!" 	$#$ 	b% G( )W )"?3 & 7)0*.37(#' '     r   c                    t          t          dz  dz            } t          t          dz  dz            }t          j        t          dz  dz                      d                    }|                    di                               d	i           }|                    di                               d
i           }t          dz  dz  dz  }t          dz  dz  dz  }t          || d         d           t          ||d         d           |                    di                               d          r|                    d          dk    rt          d          | d         |d         k    rt          d          |                     d          |                    d          k    rt          d          |                    d          |                    d          k    rt          d          t          |          \  t          |          \  d}d}fd|D             }	|		                    fd|D                        |	rt          d |	           t          |          t          |          t          t          dz  d!z            d"d#d$d%d&d'd(d)d*}
t          d+|
t          t          | d         | d         |d         |
d,         d-           d S ).Nlogzintro-render.jsonzfootage-render.jsonrl   project-manifest.jsonr   r   gate_eventsposterrv   rz   introz	intro.mp4r{   r|   artifact_sha256technical_qar7   
content_qanot_run_by_policyz8footage technical/no-content-QA contract is not verifiedrq   zfinal upstream canon mismatchsource_poster_sha256z'intro does not depend on current posterr   z)footage does not depend on current layout)
codec_nameprofiler   r   pix_fmtr_frame_rate	time_base)r   r   sample_ratechannelsr   c                    i | ]Y}                     |                               |          k    .|                     |                               |          gZS  rG   )rI   r-   footage_videointro_videos     r   
<dictcomp>zfinal.<locals>.<dictcomp>   sh       ;??3#7#7=;L;LS;Q;Q#Q#Q 	kooc""M$5$5c$:$:;#Q#Q#Qr   c                    i | ]\}                     |                               |          k    .d |z                        |                               |          g]S )audio_rG   )rI   r-   footage_audiointro_audios     r   r   zfinal.<locals>.<dictcomp>   sl       ;??3#7#7=;L;LS;Q;Q#Q#Q 	3--}/@/@/E/EF#Q#Q#Qr   z$stream-copy compatibility mismatch: 	final.mp4stream_copyFr   r   r   r   r   r   )intro_video_pathfootage_video_pathoutput_video_pathpackaging_moder~   r   r   r   r   r   r   finalr   )r   r    rq   source_intro_sha256source_footage_sha256rz   )r9   r$   r"   r#   r%   r*   r>   r+   rV   r   r   rj   r&   r'   )r   footage_receiptmanifestposter_eventlayout_event
intro_pathfootage_pathvideo_fieldsaudio_fieldsdifferencesrX   r   r   r   r   s              @@@@r   r   r   t   sC   $,)<<==E#D5L3H$HIIOz4(?-DDOOY`OaabbH<<r2266xDDL<<r2266xDDL7*[8J(?Y.>L
E"34g>>>o.?@)LLL~r2266zBB WoFYFYZfFgFgk~F~F~UVVV"#7L'MMM:;;;yy'((L,<,<=N,O,OOODEEE122l6F6FGX6Y6YYYFGGG/
;;K#3L#A#A M=gLTL      K             QO+OOPPP
OO!,// ;!>??'% G '7 $%:;$%67!01B!C-.% %     r   c            
        t          t          dz  dz            } t          j        t          dz  dz                      d                    }|                    di                               di           }|                    di                               d	i           }t          d
z  dz  }t          || d         d           |                     di                               d          r|                     d          dk    rt          d          |                     d          |                    d          k    rt          d          |                     d          |                    d          k    rt          d          t          |          t          t          d
z  dz            dddddddd	}t          d |t          t          | d!         | d         |d"         d#           d S )$Nr   zfinal-render.jsonrl   r   r   r   r   r   rv   rz   r   r   r   r   r7   r   r   z6final technical/no-content-QA contract is not verifiedr   z'final does not depend on current posterr   z'final does not depend on current layoutzfinal-upload.mp4i /i ʚ;r   r   r   `   F)	input_video_pathr   target_output_bytesmax_output_bytesr   r   r   audio_bitrate_kbpsr~   	transcoderq   r   )r   r    rq   source_final_sha256rz   )r9   r$   r"   r#   r%   r*   r>   r+   r   rj   r&   r'   )final_receiptr   r   r   
final_pathrX   s         r   r   r      s   !$,1D"DEEMz4(?-DDOOY`OaabbH<<r2266xDDL<<r2266xDDL;.J
M*;<gFFF^R0044Z@@ UMDUDUVbDcDcgzDzDzSTTT/00L4D4DEV4W4WWWDEEE/00L4D4DEV4W4WWWDEEE
OO 3E!EFF(& 
 
G +w ,-BC,->?-.) )     r   c                     t          j                    } |                     dg d           |                                 }t	                       t          t          t          d|j                              d S )NrW   )r{   r   r   )choices)	argparseArgumentParseradd_argument
parse_argsr/   r{   r   r   rW   )parserargss     r   mainr      sm    $&&F
)J)J)JKKKD	GGG%i@@LNNNNNr   __main__)r   r   r   r   )r   r   )r0   )r   r   r2   r3   r   r4   )r   r   r:   r   r;   r   r   r   )r   r   r   r?   )rW   r   rX   r4   rY   r4   r   r   )
__future__r   r   r   r"   rP   pathlibr   r$   r&   r'   r(   r   r/   r9   r>   rV   rj   r{   r   r   r   __name__r   r   r   <module>r      sk   " " " " " "             t`aa8
	(   = = = =    > > > >
       	H 	H 	H 	H* * * *Z4 4 4 4n   BO O O O zDFFFFF r   