
    Qp_j-                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	  e	e
                                          j        d         Zedz  ZdZdZd Zd Zd	 ZddZddZd Zd Zd Zedk    r e             dS dS )    N)Path   zscript/project-manifest.jsonzhttp://192.168.1.104:8022z/v1/footage-render-huyenan/jobsc                    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)handles   !script/render-footage-endpoint.py<lambda>zsha256.<locals>.<lambda>   s    &++o">">     r   )hashlibsha256openiterupdate	hexdigest)pathdigestblockr	   s      @r
   r   r      s    ^F	4 !F>>>>DD 	! 	!EMM%    	!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! s   ,A##A'*A'c                 \   |                      di                                |          }|st          d| d          t          |          }|                                r|n	t          |z  }|                                                    t                                                     |S )Nactive_pathszactive_paths.z missing)getRuntimeErrorr   is_absoluteROOTresolverelative_to)manifestkeyvaluer   s       r
   r   r      s    LL,,0055E :83888999;;D##%%6444$;DLLNNt||~~...Kr   c                     | j                             dd           |                     | j        dz             }|                    t          j        |dd          dz   d	           t          j        ||            d S )
NT)parentsexist_okz.partF   )ensure_asciiindent
utf-8encoding)	parentmkdirwith_suffixsuffix
write_textjsondumpsosreplace)r   r    parts      r
   atomic_jsonr5   #   s|    KdT222DK'122DOODJu5CCCdJU\O]]]JtTr      c                     t           j                            | |          5 }t          j        |          cd d d            S # 1 swxY w Y   d S )Ntimeout)urllibrequesturlopenr0   load)urlr9   responses      r
   get_jsonr@   *   s    			W		5	5 #y""# # # # # # # # # # # # # # # # # #s   AA
A<   c                 8   t           j                            | t          j        |d                              d          ddid          }t           j                            ||          5 }t          j        |          cd d d            S # 1 swxY w Y   d S )	NFr%   r(   zContent-Typezapplication/jsonPOST)dataheadersmethodr8   )r:   r;   Requestr0   r1   encoder<   r=   )r>   payloadr9   r;   r?   s        r
   	post_jsonrK   /   s    n$$Stz'PU/V/V/V/]/]^e/f/fq  BT  qU  ^d$  e  eG					9	9 #Xy""# # # # # # # # # # # # # # # # # #s   .BBBc                     t          j        dddddddddt          |           g
d	d	d	
          }t          j        |j                  S )Nffprobez-verrorz-show_entriesz format=duration,size,format_namezDstream=index,codec_type,codec_name,width,height,sample_rate,channelsz-ofr0   T)capture_outputtextcheck)
subprocessrunstrr0   loadsstdout)r   results     r
   proberX   5   s{    ^	D'?4VXg  jp  rw  y  AD  EI  AJ  AJ  	K	  F :fm$$$r   c                     t          j        | ddd                              d          }t          j        |                                          S )NFT),:)r%   	sort_keys
separatorsr(   )r0   r1   rI   r   r   r   )rJ   raws     r
   payload_hashr_   ?   sE    
*W5DZ
X
X
X
_
_`g
h
hC>#((***r   c                    * t          j        t                              d                    } | d         }t	          | d          }t	          | d          }t	          | d          }t	          | d          }t	          | d          }t	          | d	          }t	          | d
          }t	          | d          }	t          j        |                    d                    }
t          j        |                    d                    }t          j        |                    d                    }t          j        |                    d                    }|
                    d          dus|
                    d          |k    rt          d          |                    d          dus?|                    d          |k    s&t          |	          |                    d          k    rt          d          |                    d          dus|                    d          |k    rt          d          |                     di                               d
          dk    rt          d          |                    di           *h d}|                    d          dus|                    *          st          d          t          *fd|D                       st          d          |                    di                               d
i           }t          |          |                    d          k    rt          d          *d
                             d          t          |                    t                              k    s,*d
                             d          t          |          k    rt          d          t          t          d z             }|                    d!          d"k    s|                    d#          durt          d$          |                    d%          d&k    s2|                    d'          d(k    s|                    d)          d*k    rt          d+          t          t!          j        | d,                             d                                                    d d-         d.          }i d
t          |          d/d(d0d1d2dd3t          |	          d4t          |          d5|d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDd;dEd#dFdGdHdIi}t'          |          }d }|                                rt          j        |                    d                    }|                    d!          dJv rb|                    d          |k    rI|                    dK          |k    r0|                    dL          |k    rt          |dM                   }nt          dN          |                                rt          dO          t+          t          t,          z   |          }|                    dM          }|                    dP          }|r1|r/t          |          t          |          k    rt          dQ          t          |p|pdR          }|st          dS          t/          |dTd7d	||t          t,          z   dUz   |z   |||dt          |          t          |          dVdt          |          t          |          dVdt          |          t          |          dVg|t0          j                            t0          j        j                                                  dW           t          t,          z   dUz   |z   }	 t          |          }t          |                    d!dX                    }|dYv rnt          j        |                    d                    }|                    ||t0          j                            t0          j        j                                                  dZ           t/          ||           t=          j        d[           |dk    rt          j        |                    d                    }|                    ||t0          j                            t0          j        j                                                  d\           t/          ||           t          d]|           |                    d^          pi }|                    d          durt          d_          |                                 r|!                                j"        dAk    rt          d`          tG          |          }|                    dag           }db |D             }dc |D             } tI          |dd         de                   }!tI          tG          |	          dd         de                   }"t          |                    d4          p|                    df          pdR          }#|                    dg          p|                    dg          }$|dk    |                    d          du |#t          |          k    tK          |          dhk    o|dA                             di          djk    tK          |           dhk    o| dA                             di          dkk    tK          |          dhk    o9|dA                             d8          |dA                             d:          fdlk    tM          |!|"z
            dmk    |                    dn          du |$dok    |                    dp          du |                    dq          drv ds}%t          |%'                                          st          dt|%           t0          j                            t0          j        j                                                  }&t          j        |                    d                    }'i d!ddddud	d|dM|dL|dK|dv|'dv         dft          |                    t                              dt          |          dw|!                                j"        dx|!dy|!|"dzd{|dgdodnddpd||%|d||&d}}(t/          ||(           t          j        t                              d                    })d|)d         d	<   dd|t          |                    t                              |(d         |!ddod|&d~
|)d	<   |&|)d<   t/          t          |)           tQ          t          j)        dd||!|(d         dd7                     d S )Nr(   r)   canon_sha256promotion_receipttts_receiptlayout_receiptartwork_visual_receiptfootage_receiptfootagelayout	tts_audioverifiedTsource_canon_sha256zpromotion lineage failedartifact_sha256zTTS lineage failedzlayout lineage failedsteps	completedz*normalized layout visual gate not terminalnormalized_gates>   introrh   
left_panelright_panelz,normalized artwork visual receipt incompletec              3   R   K   | ]!}|                              d           du V  "dS )rj   TNr   ).0r   
normalizeds     r
   	<genexpr>zmain.<locals>.<genexpr>_   s:      RR3z#"":..$6RRRRRRr   z%normalized artwork visual gate failed	artifactsr   zlayout artifact driftr   z#normalized layout visual hash driftz/healthstatusok
h264_nvenczfootage health/NVENC failed
video_rootz/data/video-pipelinedefault_footage_dirz(/data/video-pipeline/GacMaiAudio/footageoutput_policyrequest_path_under_video_rootz#footage endpoint path policy failed
project_id      footage_dirpatternz*.mp4	recursiveaudiooutputseed	overwriteFwidth  height8  fpsr6   center_xi  center_yr   center_widthi`  center_heightvideo_encoderpresetp4cq   >   queuedrunning	submittedrequest_sha256r;   job_idz0existing footage receipt is not safely resumablez,footage output exists without active receiptidz#conflicting footage job identifiers z&footage create response missing job idr   /)r   r   r   )ry   rj   stagerk   r   
status_urlr;   r   healthinput_receiptscreated_responsesubmitted_atunknown>   failed	cancelledrn   )ry   latest_response
updated_at   )ry   r   	failed_atzfootage terminal failure: verificationz$footage endpoint verification failedzfootage terminal output missingstreamsc                 D    g | ]}|                     d           dk    |S )
codec_typevideort   ru   rows     r
   
<listcomp>zmain.<locals>.<listcomp>   .    IIIc(=(=(H(Hc(H(H(Hr   c                 D    g | ]}|                     d           dk    |S )r   r   rt   r   s     r
   r   zmain.<locals>.<listcomp>   r   r   formatdurationoutput_pathhorizontal_mirrorr   
codec_nameh264aac)r   r   g{Gz?mirror_appliedhflipsource_audio_discardedaudio_status>   narration_mixednarration_attached)endpoint_completedendpoint_verifiedoutput_path_exactone_h264_videoone_aac_audio
resolutionduration_matches_narrationr   horizontal_mirror_hflipr   narration_audioz'footage integrity verification failed: r   r   artifact_bytesduration_secondsduration_basis)r   
story_fullendpoint_verificationzsha256 streaming 8 MiB)independent_probechecksr   hash_methodcompleted_at)
ry   rj   r   receiptrl   r   r   r   r   r   r   )ry   rj   r   r   r   rC   )*r0   rU   MANIFEST	read_textr   r   r   r   issubsetallrT   r   r   r@   BASEintr   rI   r   r_   existsrK   CREATEr5   datetimenowtimezoneutc	isoformatr   timesleepis_filestatst_sizerX   floatlenabsvaluesprintr1   )+projectcanonpromotion_pathtts_receipt_pathlayout_receipt_pathvisual_receipt_pathreceipt_pathr   rh   r   	promotionttsrd   visual_receiptrequired_visual
layout_rowr   r   rJ   request_shar   statecreated
raw_job_idraw_idr   jobry   r   infor   videosaudiosr   source_durationresponse_outputr   r   r   previousr   latestrv   s+                                             @r
   mainr  D   sR   j++W+==>>GN#EW&9::Nw66!'+;<<!'+CDD7$566LWi((FWh''FG[))E
>33W3EEFFI
*%///AA
B
BCZ 3 = =w = O OPPNZ 3 = =w = O OPPN}}Z  ,,	>S0T0TX]0]0]5666
wwz$&&#''2G*H*HE*Q*QU[\aUbUbfifmfmn  gA  gA  VA  VA/000*%%T11^5G5GH]5^5^bg5g5g2333{{7B##H--<<GHHH##$6;;JFFFO*%%T119Q9QR\9]9]1IJJJRRRR/RRRRR DBCCC##K44882FFJf~~11112333(''3v/A/A$/G/G+H+HHHJW_L`LdLdemLnLnrxy  sA  sA  MA  MA@AAAdY&''Fzz(t##vzz,'?'?t'K'K8999zz,#999VZZH]=^=^  cM  >M  >M  QW  Q[  Q[  \k  Ql  Ql  pO  QO  QO@AAAw~gl3::7CCDDNNPPQTRTQTUWYZZD#f++A 	7 	T	
 	U 	#f++ 	 	U 	 	$ 	r 	C 	A 	 	  	!" 	$#$ 	b% G( w''KF 
<1171CCDD99X"DDDShIiIimrIrIrw|  xA  xA  BR  xS  xS  Wb  xb  xb  gl  gp  gp  qz  g{  g{  F  gF  gFx))FFQRRR==?? 	OMNNND6M733[[**
T"" 	F& 	FS__F%C%CDEEEZ/6/R00 	IGHHHL!uyafD6MC,?&,HU\)V%s3C/D/DPVWgPhPhii(#6I2J2JV\]pVqVqrr0#>Q:R:R^dex^y^yzz
 !(9J9N9NxO`Od9e9e9o9o9q9q
#
 
#
 
	 
	 
	 $v-Jz""SWWXy1122999
<1171CCDD3hN_NcNcdldudyNzNz  OE  OE  OG  OG  H  H  	I  	I  	IL%(((
1 
<1171CCDD3XM^MbMbckctcxMyMy  ND  ND  NF  NF  G  G  	H  	H  	HL%(((@@@AAA77>**0bL
##4//ABBB>> >v{{}}499<=====Dhhy"%%GIIWIIIFIIWIIIFT(^J/00HE%LL2:>??O#''(++Ksww}/E/EKLLO 344]8H8HI\8]8]$3)--j99TA,F;f++*Tvay}}\/J/Jf/TV)RfQimmL.I.IU.R&kkQ&lF1IMM',B,BF1IMMRZD[D[+\`l+l&)(_*D&E&E&M&**+;<<D#4#?"."2"23K"L"LPT"T'++N;;?hh F v}} OMVMMNNN



 1 5
6
6
@
@
B
BCz,00'0BBCCH	+	)4	18)	EZ\a	&	#W	.>	 	(#34	 7DSI[I[\`IaIaEbEb	 	6&>>		 ,<V[[]]=R		
 	H	
 '78[j8k8k	 	 	 0CG	 N^_c	 	!$	 >BV/GY\	 	 	G g&&&Z**G*<<==F!,F7OI#.DF_bcoc{c{  }A  dB  dB  `C  `C  X_  `q  Xr  HP  dh  F  bf  x{  |  |F9F<&!!!	$*em  zA  BS  zT  U  U  di  j  j  j  k  k  k  k  kr   __main__)r6   )rA   )r   r   r0   r2   rR   r   urllib.requestr:   pathlibr   __file__r   r"   r   r   r   r   r   r5   r@   rK   rX   r_   r  __name__ r   r
   <module>r     s?      				               tH~~'*00"	*      # # # #
# # # #% % %+ + +
Yk Yk Ykx zDFFFFF r   