
    3]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	m
Z
  e
e                                          j        d         Zedz  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.json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/rebuild-intro-v2.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| d          t	          |          }|                                s
t          |z  }	 |                                                    t                                                     n%# t          $ r}t          d|           |d }~ww xY w|S )Nactive_pathszactive_paths.z is missingzactive path escapes project: )
get
isinstancer   RuntimeErrorr   is_absoluteROOTresolverelative_to
ValueError)r   r   valuer   excs        r   resolve_activer(      s    \\.))/R44S99EeS!! = =;3;;;<<<;;D d{K""4<<>>2222 K K K@3@@AAsJKKs   >C 
C$CC$r&   Nonec                   | j                             dd           t          j        |dd          dz                       d          }t          j        d| j         d| j         	          \  }}	 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.)prefixdir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_jsonrJ   '   s   KdT222Ju5;;;dBJJ7SSD'749'7'7'7T[IIIHBYr4   	&FLLLLNNNHV]]__%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	
47>>$ 	IdOOOOO	 	27>>$ 	IdOOOO	s1   2D: AC#D: #C''D: *C'+D: :6E0c                |    t          j        t          j        dddddddt	          |           gd	                    S )
Nffprobe-verrorz-show_entriesz[format=duration:stream=codec_name,codec_type,width,height,sample_rate,channels,r_frame_ratez-ofr9   T)text)r9   loads
subprocesscheck_outputr   )r   s    r   proberS   6   sM    :j-4/evs4yy/ 	     r   intc                 t   t          j        t                              d                                        d          dk    rt          d          d} fd| D             }t          j        |d                             d                    }t          j        |d	                             d                    }t          j        |d
                             d                    }|                    d          }|                    d          dus|                    d          k    rt          d          |                    d          dus0|                    d          |k    s|                    d          durt          d          |                    d          dus0|                    d          |k    s|                    d          durt          d          t          |d                   }|                    d          |k    s|                    d          |k    rt          d                              d          pi                     d          pi }|                    d          }t          |t                    r|st          d          t          |z  }	t          j        |	                    d                    }
|
                    d          dk    s0|
                    d          dus|
                    d          |k    rt          d          |
                    d          |
                    d          |
                    d          d }|
                                D ]F\  }}||         }|                                rt          |          |k    rt          d!|           G|d"                                         s|d                                         rt          d#          t          |d$                   }t          |d%                   }t          |d&                   }t          |d'         d(                   }t          |d'         d(                   }t          |d'         d(                   }t          |d)z
            d*k    st          ||z
  d)z
            d+k    rt          d,          |d"         j                            dd-           t#          j        g d.d/d0d1d2d3d4t          |d                   d4t          |d&                   d5|d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHt          |d"                   dI           t          |d"                   }t          |d'         d(                   }|                    dJg           }dK |D             }dL |D             }t          ||z
            dMk    ot'          |          dNk    ot'          |          dNk    o|dO                             dP          dQk    ott)          |dO                             dRdO                    t)          |dO                             dSdO                    fdTk    o|dO                             dP          dBk    }i d|rdndUd|d|dddVdWdXt          |d	                   t          |d	                   dYdZt          |d
                   t          |d
                   dYd[t          |d                   d\|d]dd^t          |	          t          |	          dYd_t          |d$                   d|d$         d`t          |d%                   d|d%         da|dbt          |d&                   |d&         |d:t          |d"                   t          |d"                   |t          ||z
            |t*          j                            t*          j        j                                                  dcdd
}t5          |d         |           t7          t          j        |d         |t          |d"                   |t          |d                   dedfg                     |rdOndNS )hNr2   )encodingactive_versionv2zactive_version is not v2)	promotion_receiptartwork_visual_receiptorientation_receiptintro_normalizedintro_voiceintro_silenceintro_audiointrointro_receiptc                2    i | ]}|t          |          S  )r(   ).0r   projects     r   
<dictcomp>zmain.<locals>.<dictcomp>G   s%    ???3S.#..???r   rY   rZ   r[   canon_sha256verifiedTz!promotion gate is absent or stalesource_canon_sha256user_approvedz4poster Visual Direction/Text Gate is absent or stalez*poster Orientation Gate is absent or staler\   normalized_sha256z0normalized poster differs from approved receiptsposter_v2_promotionsuperseded_pathsra   z#superseded intro receipt is missingstatus	completedz3prior intro audio authority receipt is not verifiedvoice_sha256silence_sha256intro_full_sha256)r]   r^   r_   zreused intro audio drift: r`   z9v2 intro output/receipt already exists and requires auditr]   r^   r_   formatdurationg       @gMbP?g{Gz?z/reused intro audio duration verification failedr+   ffmpegrM   rN   z-yz-loop1z-iz-tz.6fz-r30z-c:vlibx264z-presetmediumz-crf18z-pix_fmtyuv420pz-c:aaacz-ar48000z-ac2z	-movflagsz
+faststart)checkstreamsc                D    g | ]}|                     d           dk    |S )
codec_typevideor   rd   items     r   
<listcomp>zmain.<locals>.<listcomp>~   .    LLLt$((<*@*@G*K*Kd*K*K*Kr   c                D    g | ]}|                     d           dk    |S )r   audior   r   s     r   r   zmain.<locals>.<listcomp>   r   r   g:m?r   r   
codec_nameh264widthheight)i  i8  failedrebuild_reasonz:user-approved cinematic poster replaces rejected v1 posterposter_visual_receipt)r   r   poster_orientation_receiptposter_pathposter_sha256$audio_reused_without_new_tts_requestprior_intro_receipt
voice_pathsilence_pathsilence_duration_secondsintro_audio_pathzsha256 streaming 8 MiB)
intro_audio_sha256audio_duration_secondsencoderoutput_pathartifact_sha256video_duration_secondsduration_delta_secondsindependent_probecompleted_athash_method)rn   rh   outputduration_secondsreceiptFr/   )r9   rP   PROJECT_MANIFEST	read_textr   r    r   r   r   r"   itemsrF   rS   floatabsr7   r8   rQ   runlenrT   datetimenowtimezoneutc	isoformatrJ   printr:   )keyspaths	promotionvisualorientationcanonposter_hash
supersededold_receipt_valueold_receipt_patholdexpectedr   r   r   voice_probesilence_probeaudio_probevoice_durationsilence_durationaudio_durationinfort   r   videosaudiosrh   r   re   s                               @r   mainr   >   sg
   j)33W3EEFFG{{#$$,,5666D
 @???$???E
5!45???QQRRIZ67AA7ASSTTF*U#89CCWCUUVVKMM.))E}}Z  ,,^9T9T0T0T>???zz*T))VZZ8M-N-NRW-W-W[a[e[efu[v[v  C  \C  \CQRRRz""$..+//BW2X2X\a2a2aepetet  vE  fF  fF  NR  fR  fRGHHH1233Kzz%&&+55I\9]9]al9l9lMNNN++344:??@RSSYWYJ"77'-- B5F B@AAA//
*%///AA
B
BC
wwxK''377:+>+>d+J+JcggVkNlNlpuNuNuPQQQww~..!122ww233 H
  ~~'' C CVSz{{}} 	Ct 6 6ACAABBB !7W~ X%"8"?"?"A"A XVWWWm,--K%011Mm,--K;x0<==N]84Z@AA;x0<==N
c!""U**c.>2QTW2W.X.X[_._._LMMM	'Nt<<<N !%'.0359;>uEW?X;Y;Y%&'')-2@/F/FHLNR 	  % '/ 17 9= ?I KT 		 	 	 &	 (-	 /2	 4?	 AM	
 	E'N     w  DT(^J/00Hhhy"%%GLLwLLLFLLwLLLFH~%&&.8 	1KK1	1!$V!1	11IMM,''61	1 w**++Sx1K1K-L-LMQ]]	1 1IMM,''50 7++x9CXu&6 	V 	 #e4L.M*N*NZ`afg  bA  [B  [B  "C  "C	
 	%s59N3O/P/P\bchi~c  ]A  ]A  'B  'B 	s5!3455 8G 	/ 	,<(=(=P`IaIabb 	c%.// 2@-AX 	E/233 6FxP_G` 	#$4 	Cm 455 NVVcMd"0Y5>**veGn?U?U"*c(UcJcFdFd! )--h.?.CDDNNPP/%  G( o&000	$* 1xSVW\]dWeSfSf  }E  RU  V[  \k  Vl  Rm  Rm  n  n  }B  C  C  C  D  D  D11ar   __main__r   Fz: )rn   rh   rN   r   )file)r   r   r   r   )r   r   r   r   r   r   )r   r   r&   r   r   r)   )r   r   r   r   )r   rT   )
__future__r   r   r   r9   r?   rQ   sysr<   pathlibr   __file__r#   r,   r"   r   r   r(   rJ   rS   r   __name__exit	Exceptionr'   r   r:   typestderrrc   r   r   <module>r      s   " " " " " "    				     



       tH~~'*88             _  _  _  _ D z   jdjH%TTRUYYM_JhJhcfJhJhiix}~~~  FI  FP  	Q  	Q  	Q  	Q s   1B C$A	CC$