
    ]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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!dZd"dZd#dZd$dZd%dZd&dZd'dZedk    rw	  ej         e                       dS # e$ rTZ e ej         dd e!e          j         de dd          ej"                     ej        d           Y dZ[dS dZ[ww xY wdS )(    )annotationsN)Path   zscript/project-manifest.jsonzhttp://192.168.1.104:8022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)handles   script/run-footage-job.py<lambda>zsha256.<locals>.<lambda>   s    &++o">">     r   )hashlibsha256openiterupdate	hexdigest)r   digestchunkr   s      @r   r   r      s    ^F	4 !F>>>>DD 	! 	!EMM%    	!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! s   ,A##A'*A'manifestdictkeyc                   |                      d          pi                      |          }t          |t                    r|st          d|           t	          |          }|                                s
t          |z  }|                                                    t                                                     |S )Nactive_pathszmissing active_paths.)	get
isinstancer   RuntimeErrorr   is_absoluteROOTresolverelative_to)r   r   valuer   s       r   r#   r#      s    \\.))/R44S99EeS!! : :8388999;;D d{LLNNt||~~...Kr   r%   Nonec                   | j                             dd           t          j        |dd          dz                       d          }t          j        | j         d| j         dd	
          \  }}	 t          j	        |d          5 }|
                    |           |                                 t          j        |                                           d d d            n# 1 swxY w Y   t          j        ||            t          j                            |          rt          j        |           d S d S # t          j                            |          rt          j        |           w w xY w)NT)parentsexist_okF   )ensure_asciiindent
utf-8.z.tmp)dirprefixsuffixwb)parentmkdirjsondumpsencodetempfilemkstempnameosfdopenwriteflushfsyncfilenoreplacer   existsunlink)r   r%   datafdr;   r   s         r   atomic_jsonrG   (   s   KdT222Ju5;;;dBJJ7SSDDK8HDI8H8H8HQWXXXHBYr4   	&FLLLLNNNHV]]__%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	
47>>$ 	IdOOOOO	 	27>>$ 	IdOOOO	s1   3D; AC$D; $C((D; +C(,D; ;6E1urlc                    t           j                            | d          5 }t          j        |                                                    d                    cd d d            S # 1 swxY w Y   d S )N   timeoutr.   )urllibrequesturlopenr6   loadsr   decode)rH   responses     r   get_jsonrS   7   s    			R		0	0 ;Hz(--//0099::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s   9A((A,/A,payloadc                   t           j                            | t          j        |d                              d          ddid          }t           j                            |d	          5 }t          j        |                                	                    d                    cd d d            S # 1 swxY w Y   d S )
NFr+   r.   zContent-Typezapplication/jsonPOST)rE   headersmethod<   rK   )
rM   rN   Requestr6   r7   r8   rO   rP   r   rQ   )rH   rT   rN   rR   s       r   	post_jsonr\   <   s    n$$Ze444;;GDD!34	 %  G 
				4	4 ;z(--//0099::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s   .9B44B8;B8c                |    t          j        t          j        dddddddt	          |           gd	                    S )
Nffprobez-verrorz-show_entrieszSformat=duration,size:stream=codec_name,codec_type,width,height,sample_rate,channelsz-ofr6   T)text)r6   rP   
subprocesscheck_outputr   )r   s    r   proberc   G   sM    :j-4/]vs4yy/ 	     r   intc                    t          j        t                              d                    fddD             } t          j        | d                             d                    }t          j        | d                             d                    }                    d          }|                    d          d	k    s0|                    d
          dus|                    d          |k    rt          d          |                    d          d	k    s0|                    d
          dus|                    d          |k    rt          d          |                    d          t          | d                   k    rt          d          |                    di                               t          | d                             t                              i           }|                    d          t          | d                   k    rt          d          i dt          | d                   dddddddt          | d                   dt          | d                   ddd d!d"d#d$d%d&d'd(d)d*dd+d,d-d%d.d/d0d1d2d3i}| d4         }d }|
                                rt          j        |                    d                    }|                    d          d	k    r&|                    d
          du rt          d5          |                    d          d6v rN|                    d7          }|st          d8          |                    d9          |k    rt          d:          n)| d         
                                rt          d;          |t          t           d<|          }	|	                    d7          p|	                    d=          }t          |t                    r|st          d>|	           t          ||	                    dd?          d!||||	t          | d                   t          | d                   t          j                            t          j        j                                                  d@	           	 t)          t           dA|           }
|
                    d          }|d6v rt          j        |                    d                    }|                    |d!|
t          j                            t          j        j                                                  dB           t          ||           t-          j        dC           |d	k    rt          j        |                    d                    }|                    |pdDd!|
t          j                            t          j        j                                                  dE           t          ||           t          dF|           	 |
                    dG          pi }t1          |
                    ddH                    }| d                                         rt5          | d                   ni }|                    dIg           }dJ |D             }dK |D             }t7          |                    dL          pi                     dMd                    }t7          |                    dNd                    }|                    d
          du || d         k    | d                                         o"| d                                         j        dk    |                    d"          d#k    o|                    d$          d%k    |                    dO          du |                    dP          du |                    dQ          dRv |                    dS          dTv t=          |          dUk    o|d                             dV          dWk    t=          |          dUk    o|d                             dV          dXk    t=          |          dUk    o=|d                             d"          d#k    o|d                             d$          d%k    |dk    ot?          ||z
            dYk    dZ}tA          |!                                          }|rd	ndD|||||
d[ |"                                D             t          | d                   t          | d                   t          | d                   | d                                         rt          | d                   nd | d                                         r| d                                         j        nd ||t          j                            t          j        j                                                  d\}t          ||           tG          t          j$        |d         |||d         |d]         t          |          d^d!_                     |rdndUS )`Nr.   )encodingc                2    i | ]}|t          |          S  )r#   ).0r   projects     r   
<dictcomp>zmain.<locals>.<dictcomp>Q   s1       CS''3''   r   )layoutlayout_receipt	tts_audiotts_receiptfootagefootage_receiptrm   ro   canon_sha256status	completedverifiedTsource_canon_sha256z'layout receipt absent, failed, or stalez$TTS receipt absent, failed, or staleartifact_sha256rn   zTTS audio drift	artifactsrl   r   zlayout artifact driftfootage_dirz(/data/video-pipeline/GacMaiAudio/footagepatternz*.mp4	recursiveaudiooutputrp   seedr   	overwriteFwidthi  heighti8  fpsrJ   center_xi  center_ycenter_widthi`  center_heightvideo_encoder
h264_nvencpresetp4cq   rq   z>footage already completed and requires audit, not resubmission>   queuedrunning	submittedjob_idz$running footage receipt lacks job_idrN   z3existing job payload differs from current authorityz)footage output exists without job receiptz/v1/footage-render-huyenan/jobsidzsubmit response lacks job_id: r   )	rs   ru   rv   r   rN   submit_responselayout_sha256narration_sha256submitted_atz /v1/footage-render-huyenan/jobs/)rs   ru   last_job_response
updated_at   failed)rs   ru   terminal_job_response	failed_atzfootage job terminal failure: verification streamsc                D    g | ]}|                     d           dk    |S )
codec_typevideor   ri   items     r   
<listcomp>zmain.<locals>.<listcomp>   .    LLLt$((<*@*@G*K*Kd*K*K*Kr   c                D    g | ]}|                     d           dk    |S )r   r|   r   r   s     r   r   zmain.<locals>.<listcomp>   r   r   formatdurationduration_secondsmirror_appliedsource_audio_discardedaudio_status>   okpresentru   narration_mixednarration_attachedplaceholder_remaining>   FNr   
codec_nameh264aacgQ?)endpoint_verifiedoutput_exactoutput_exists
resolutionr   r   r   no_placeholderone_h264_videoone_aac_audioprobe_resolutionduration_matches_narrationc                     i | ]\  }}|||d S ))ru   r%   rh   )ri   r   r%   s      r   rk   zmain.<locals>.<dictcomp>   s'    jjjZSRW%%%H%Hjjjr   )rs   ru   rv   r   rN   r   verification_checksr   r   output_pathrw   bytesr   independent_probecompleted_atr   )rs   ru   r   rw   r   receiptrV   )%r6   rP   MANIFEST	read_textr   r    r   r   r$   r"   rC   r\   BASEr   rG   datetimenowtimezoneutc	isoformatrS   r   timesleepr   is_filerc   floatstatst_sizelenabsallvaluesitemsprintr7   )pathsrm   ro   canonlayout_artifactrT   receipt_pathr   priorrR   jobrs   currentfailurer   r}   output_prober   videosaudiosoutput_durationnarration_durationchecksru   resultrj   s                            @r   mainr   O   s
   j++W+==>>G    4   E Z&6 7 A A7 A S STTN*U=1;;W;MMNNKKK''E(##{22n6H6H6T6T\`6`6`drdvdv  xM  eN  eN  RW  eW  eWDEEEx  K//;??:3N3NVZ3Z3Z^i^m^m  oD  _E  _E  IN  _N  _NABBB())VE+4F-G-GGG,---$((b99==c%/B]B]^bBcBc>d>dfhiiO8$$uX(?(???2333#eHo&&A 	7 	T	
 	U;'(( 	#eI&'' 	 	U 	 	$ 	r 	C 	A 	 	  	!" 	$#$ 	b% G( *+LF H
<1171CCDD99X+--%))J2G2G42O2O_```99X"DDDYYx((F K"#IJJJyy##w.."#XYYY	y		 	 	"	" HFGGG~EEEwOOh''=8<<+=+=&#&& 	Lf 	LJJJKKKLll8[99#('#E(O44 &u['9 : :$-11(2C2GHHRRTT
#
 
#
 
	 
	 
	$HHHHII""777j!7!7!7!I!IJJGNN !%(&/33H4E4IJJTTVV	     g...JqMMM[  j!7!7!7!I!IJJGNN ,H!),%.2283D3HIISSUU	     g...HHHIII77>**0bL#''(B''((F.3I.>.F.F.H.HP5y)***bLy"--GLLwLLLFLLwLLLF\--h77=2BB:qQQRRO{/A1EEFF)--j99TA%	"22y)1133[i8H8M8M8O8O8WZ[8["&&w//47^L<L<LX<V<VZ^<^&**+;<<D"."2"23K"L"LPT"T$((88  =C  C&**+BCC}Tf++*Tvay}}\/J/Jf/TV)RfQimmL.I.IU.RKK1,sw1G1G41OsTZ[\T]TaTabjTkTkosTs&81&<&r_WiEiAjAjnrAr F 6==??##H!)7++x$!$jj[a[g[g[i[ijjjh00"5#5665+,,7<Y7G7O7O7Q7Q[6%	"2333W[49)4D4L4L4N4NXy!&&((00TX+) )--h.?.CDDNNPP F" f%%%	$*"!"34|$$        11ar   __main__r   Fz: )rs   ru   r_   rV   )file)r   r   r   r   )r   r   r   r   r   r   )r   r   r%   r   r   r&   )rH   r   r   r   )rH   r   rT   r   r   r   )r   r   r   r   )r   rd   )#
__future__r   r   r   r6   r<   ra   sysr9   r   urllib.errorrM   urllib.requestpathlibr   __file__r#   r(   r"   r   r   r   rG   rS   r\   rc   r   __name__exit	Exceptionexcr   r7   typestderrrh   r   r   <module>r      s$   " " " " " "    				     



                tH~~'*00"         ; ; ; ;
; ; ; ;   Q  Q  Q  Q h z   jdjH%TTRUYYM_JhJhcfJhJhiix}~~~  FI  FP  	Q  	Q  	Q  	Q s   B! !C:&A	C55C: