
    f`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  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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)atomic_write_jsoncanonical_payload_sha256endpoint_is_idleselect_idle_endpoint   zstory/promotion-report.jsonzlog/intro-render.jsonzlog/footage-job.jsonzoutput/intro/intro.mp4zoutput/footage/footage.mp4zoutput/final.mp4zlog/final-intent.jsonzlog/final-submission.jsonfinalc                    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-final.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ddt          |           g
d	d	d	
          }t          j        |j                  S )Nffprobez-verrorz-show_entrieszformat=duration,sizez9stream=index,codec_name,width,height,sample_rate,channelsz-ofjsonT)capture_outputtextcheck)
subprocessrunstrr!   loadsstdout)r   results     r   prober+       s    ^YgH^`o  rm  ot  v|  ~A  BF  ~G  ~G  H  Y]  dh  pt  u  u  uF:fm$$$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urlopenr!   load)urlr/   responses      r   get_jsonr6   %   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.   )r0   r1   Requestr!   dumpsencoder2   r3   )r4   payloadr/   r1   r5   s        r   	post_jsonrD   *   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                     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          |k    r|
                    d          |k    r|
                    d	          t          t                    k    r|
                    d	          t          t                    k    rV|
                    d
i           
                    d          du r+|
                    d
i           
                    d          du st          d          t          t                    t          t                    }}t          d |
                    dg           D                       st          d          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          t          t                    t          t                    t          t,                    dddd }d!|v rt          d"          t/          t0                    \  }}t3          ||          st          d#          t5          |d$         d%                   t5          |d$         d%                   z   }d&d'd(t0          d)||t7          |          |t          t,                    ||t5          |d$         d%                   t5          |d$         d%                   t9          j        t<          j                                                   d*}tC          t           |           tE          ||z   |          }|
                    d          }|r|
                    d          d+vrt          d,          |#                    d-|t9          j        t<          j                                                   |d.           tC          t           |           tC          t$          |           t)          t          j        |||
                    d          d/d01                     dS )2Nc              3   @   K   | ]}|                                  V  d S )N)exists).0r   s     r   	<genexpr>zmain.<locals>.<genexpr>2   s-      
2
2t{{}}
2
2
2
2
2
2r   z)verified intro/footage inputs are missingzutf-8)encodingspoken_sha256verifiedTsource_canon_sha256output_sha256server_verificationmirror_appliedsource_audio_discardedzauthority receipt mismatchc              3   H   K   | ]}|                     d           dk    V  dS )
codec_nameaacN)get)rH   ss     r   rI   zmain.<locals>.<genexpr>E   s3      VVquu\""e+VVVVVVr   streamsz&footage does not carry narration audioinput_sha256z8prior attempt belongs to different authority/input bytesbase_urljob_id	jobs_path/status>   queuedrunning	completed)rZ   rY   r]   resumedr   z;existing ambiguous/terminal attempt requires reconciliationzunreceipted output existsr,   i  i8  )intro_video_pathfootage_video_pathoutput_video_pathfpswidthheightmain_audio_pathz.final payload must not include main_audio_pathz"selected replica is no longer idleformatdurationr
   015z015-final-v1creating)schema_version
project_idrun_idstager]   rY   r[   request_sha256rX   output_pathrM   expected_duration_secondsintro_duration_secondsfootage_duration_seconds
created_at>   r^   r_   z/POST result ambiguous; reconcile pinned replica	submitted)r]   rZ   submitted_atrC   )rZ   rY   r]   F)ensure_ascii)$	PROMOTIONINTRO_RECEIPTFOOTAGE_RECEIPTINTROFOOTAGEanyRuntimeErrorr!   r(   	read_textrU   r   r+   r'   relative_toPROJECTINTENTrG   
SUBMISSIONr6   printrA   OUTPUTr	   STAGEr   floatr   r   nowr   utc	isoformatr   rD   r   )required	promotionintro_receiptfootage_receiptcanonintro_probefootage_probeinput_hashesrecord_pathpriorjobrC   rY   r[   expectedintentcreatedrZ   s                     r   mainr   0   si   =/5'JH

2
2
2
2
222 HFGGG
9...@@AAIJ}666HHIIMj!:!:G!:!L!LMMOMM/**Ej!!T))j))T11
++t33344== 566%??o..#e**<<00CLL@@ 5r::>>?OPPTXXX 5r::>>?WXX\```7888!&uuW~~KVV]5F5FyRT5U5UVVVVV ECDDD))'2233SZZWEXEXY`EaEaAbAbdghodpdpqL}} 
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#&u::S\\hklrhshs|~  JN  Z^  _  _GG##KLLL.u55HiHi00 A?@@@[*:677%h@WXb@c:d:ddH5NUZfp9H`ahHiHi  |H6{{5_g"'H(=j(I"J"Jhmn{  }E  oF  GQ  oR  iS  iSl8<00::<< 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]^^mr
s
s
sttt1r   __main__zFinal blocked: )file)r,   )(r   r!   r%   sysurllib.requestr0   r   r   pathlibr   render_poolr   r   r   r	   __file__resolveparentsr   rz   r{   r|   r}   r~   r   r   r   r   r   r+   r6   rD   r   __name__exit	Exceptionexcr   r'   stderr r   r   <module>r      s         



     ' ' ' ' ' ' ' '       k k k k k k k k k k k k
$x..
 
 
"
"
*1
-33	1122**
0
0	%	%	*	*22
  % % %
# # # #
# # # #< < <~ z   ##c((*<<<< s   B3 3C18.C,,C1