
    
`j                        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mZ d dlm	Z	 d dl
mZmZmZmZmZ  e	e                                          j        d         Zedz  Zedz  Zedz  Zed	z  Zed
z  Zedz  Zedz  Zedz  ZdZdZd Zd ZddZ ddZ!d Z"e#dk    r\	  ej$         e"                       dS # e%$ r9Z& e'd e(e&          z   ej)                    ej$        d           Y dZ&[&dS dZ&[&ww xY wdS )    N)datetimetimezone)Path)RENDER_POOLSatomic_write_jsoncanonical_payload_sha256endpoint_is_idleselect_idle_endpoint   zlog/tts-verification.jsonzlog/tts-pronunciation.jsonzimage/layout-manifest-r2.jsonzaudio/story-full.wavzimage/layout-1920x1080-r2.pngzoutput/footage/footage.mp4zlog/footage-intent.jsonzlog/footage-submission.jsonfootagei>  c                    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/submit-footage.py<lambda>zsha.<locals>.<lambda>   s    &++o">">     r   )hashlibsha256openiterupdate	hexdigest)pathdigestblockr   s      @r   shar      s    ^F	4 !F>>>>DD 	! 	!EMM%    	!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! s   ,A##A'*A'c                     t          j        dddddddt          |           gddd	          }t          |j                                                  S )
Nffprobez-verrorz-show_entrieszformat=durationz-ofzdefault=nw=1:nk=1T)capture_outputtextcheck)
subprocessrunstrfloatstdoutstrip)r   results     r   durationr,   !   sw    ^YgHY[`buwz{  xA  xA  B  SW  ^b  jn  o  o  oF$$&&'''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urlopenjsonload)urlr0   responses      r   get_jsonr8   &   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 )	NT),:)	sort_keys
separatorszContent-Typezapplication/jsonPOST)dataheadersmethodr/   )r1   r2   Requestr4   dumpsencoder3   r5   )r6   payloadr0   r2   r7   s        r   	post_jsonrF   +   s    n$$Stz'T^h/i/i/i/p/p/r/r  ~L  N`  }a  jp$  q  qG					9	9 #Xy""# # # # # # # # # # # # # # # # # #s   .BBBc                  x   t           t          t          t          t          f} t          d | D                       rt          d          t          j        t           	                    d                    }t          j        t          	                    d                    }t          j        t          	                    d                    }|
                    d          }|
                    d          du r|
                    d          du r|
                    d          du r|
                    d	          d
u r||
                    d          |
                    d          k    rO|
                    d          |
                    d          k    r"|
                    d          t          t                    k    r|
                    d          t          t                    k    r|
                    d          du r|
                    d          dk    r|
                    d          dk    r|
                    di           
                    d          du rX|
                    d          |k    r?|
                    di           
                    d          t          t                    k    st          d          t          t                              t                              t          t                    t          t                              t                              t          t                    t          t                              t                              t          t                    t          t                              t                              t          t                    i}t                                          st"                                          rQt"                                          rt"          nt          }t          j        |	                    d                    }|
                    d          |k    s|
                    d          |k    rt          d          |
                    d          r|
                    d          rt%          |d         |d         z   dz   |d         z             }|
                    d          dv rGt'          t          j        |d         |d         |
                    d          dd                     d S t          d!          t*                                          rt          d"          i d#t          t                    d$d%d&d'd(dd)t          t                    dt          t*                    d*t,          d+d
d,d-d.d/d0d1d2d3d4d d5d6d7d/d8d9d:d;d<d=i}	t/          t0                    \  }
}t3          |
|          st          d>          t5          j        t8          j                                                  }d?d@dAt0          dB|
|t?          |	          |t          t*                    |tA          t                    |dC}tC          t          |           tE          |
|z   |	          }|
                    d          }|r|
                    d          dDvrt          dE          |#                    dF|t5          j        t8          j                                                  |	dG           tC          t          |           tC          t"          |           t'          t          j        ||
|
                    d          t          t"                    dHd
I                     d S )JNc              3   @   K   | ]}|                                  V  d S )N)exists).0r   s     r   	<genexpr>zmain.<locals>.<genexpr>3   s-      
2
2t{{}}
2
2
2
2
2
2r   z,verified TTS/local-layout inputs are missingzutf-8)encodingsource_canon_sha256verifiedTpronunciation_verifiedsemantic_content_changedFsource_sha256projection_sha256spoken_narration_sha256pronunciation_receipt_sha256output_sha256status	completedbuilder_locationagent_local	visual_qaoutputr   z#TTS/local-layout authority mismatchinput_sha256z8prior attempt belongs to different authority/input bytesbase_urljob_id	jobs_path/>   queuedrunningrW   )r^   r]   rV   resumedr   z;existing ambiguous/terminal attempt requires reconciliationzunreceipted output existslayoutfootage_dirz(/data/video-pipeline/GacMaiAudio/footagepatternz*.mp4	recursiveaudioseed	overwritewidthi  heighti8  fpsr-   center_xi  center_ycenter_widthi`  center_heightvideo_encoder
h264_nvencpresetp4cq   z"selected replica is no longer idler   016z016-footage-v1creating)schema_version
project_idrun_idstagerV   r]   r_   request_sha256r\   output_pathrM   expected_duration_seconds
created_at>   ra   rb   z/POST result ambiguous; reconcile pinned replica	submitted)rV   r^   submitted_atrE   )r^   r]   rV   
submission)ensure_ascii)$TTSPRONUNCIATIONLAYOUTAUDIOLAYOUT_IMAGEanyRuntimeErrorr4   loads	read_textgetr   r'   relative_toPROJECTINTENTrI   
SUBMISSIONr8   printrC   OUTPUTSEEDr
   STAGEr	   r   nowr   utc	isoformatr   r,   r   rF   r   )requiredttspronunciationrd   canoninput_hashesrecord_pathpriorjobrE   r]   r_   r   intentcreatedr^   s                   r   mainr   1   sH   ]FE<@H

2
2
2
2
222 KIJJJ
*S]]G]44
5
5CJ}666HHIIMZ(('(::;;FGG)**E
t##GG,--55j))T11899UBBGGO$$(9(9:M(N(NNNGG-..-2C2CO2T2TTTGG233s=7I7IIIGGO$$E

22JJz""d**JJx  K//JJ)**m;;JJ{B''++J774??JJ,--66JJx$$((22c,6G6GGG@AAAEg&&''UL$$W--..L0A0AFw''((#f++M%%g..//]1C1C	L }} 
Z*++-- 
Z$.$5$5$7$7CjjV
;00'0BBCC99*++u44		.8Q8QUa8a8aYZZZ99Z   	UYYx%8%8 	5,u[/AACG%PX/YZZCwwx  $FFFdjE(OzIZfifmfmnvfwfw  EI  "J  "J  K  K  L  L  LqXYYY}} 86777#l##%24^`ikrt  BFU%s6{{4:DBMu 	   (-b 3=c DNq Sabe hwx| 		 (0	 8<R	 G /u55HiHi00 A?@@@
,x|
$
$
.
.
0
0C5<LW\hr9H`ahHiHi  |H6{{5_ghm_n_n  B F
 ff%%%9,g66G[[""F NW[[**2GGGLMMM
MM[FHLYaYeLfLfLpLpLrLr  @G  H  H  I  I  Iff%%%j&)))	$*HT\H]H]mpq{m|m|}}  MR  S  S  S  T  T  T1r   __main__zFootage blocked: )file)r-   )*r   r4   r%   sysurllib.requestr1   r   r   pathlibr   render_poolr   r   r   r	   r
   __file__resolveparentsr   r   r   r   r   r   r   r   r   r   r   r   r,   r8   rF   r   __name__exit	Exceptionexcr   r'   stderr r   r   <module>r      s         



     ' ' ' ' ' ' ' '       y y y y y y y y y y y y y y
$x..
 
 
"
"
*1
-++66	2	2((88	/	/	,	,44
  ( ( (
# # # #
# # # #D D DN z   !CCHH,3:>>>> s   B7 7C5<.C00C5