
    \jC              
         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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.jsonu   Các bạn đang nghe truyện được phát từ Gác Mái Audio, chúc các bạn có những giây phút nghe truyện vui vẻ. Hãy ủng hộ chúng tôi bằng cách like video và đăng ký kênh.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/resume-intro-encode.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   7   sM    :j-4/evs4yy/ 	     r   intc                 t   t          j        t                              d                                        d          pi } fddD             }t
          |                     dd          z  }|                     d          d	k    s0|                     d
          dk    s|                     d          durt          d          t          j        |                    d                    }|                    d          dk    s0d|                    dd          vr'd	|                    dd          vrt          d          t          j        |d                             d                    }t          j        |d                             d                    }|                    d          }|                    d          dus0|                    d          dus|                    d          |k    rt          d          |d         |d         |d         |d         g}d |D             }|rt          d|           |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(          t          d) |	|
|fD                       st          d*          |d          j                            dd+           t          j        g d,d-dd.d/d0d1t!          |d                   d1t!          |d                   d2|d3d4d5d6dd7d8d9d:d;d<d=d>d?d@dAdBdCdDt!          |d                    dE           t          |d                    }t          |d#         d$                   }|                    dFg           }dG |D             }dH |D             }t          ||z
            dIk    ot#          |          dJk    ot#          |          dJk    o|dK                             dL          dMk    ott%          |dK                             dNdK                    t%          |dK                             dOdK                    fdPk    o|dK                             dL          d>k    }i d|rdQndd|d|dRdSdTt!          |          t'          |          dUdVddWt(          dXt!          |d                   dYt'          |d                   dZt!          |d                   d[t'          |d                   d\|d]t!          |d                   d^t'          |d                   d_|d`t!          |d                   dat'          |d                   |dt!          |d                    t'          |d                    |t          ||z
            |t*          j                            t*          j        j                                                  dbdc	}t5          |d!         |           t7          t          j        |d         ||t!          |d!                   dddef                     |rdKndJS )gNr2   )encodingintro_encoder_recoveryc                2    i | ]}|t          |          S  )r(   ).0r   projects     r   
<dictcomp>zmain.<locals>.<dictcomp>B   s1       3S.#..   r   )promotion_receiptlayout_receiptintro_normalizedintro_voiceintro_silenceintro_audiointrointro_receiptfrom_receipt failed_encoder
h264_nvencrecovery_encoderlibx264
tts_reusedTz)intro encoder recovery contract is absentstatusfailedzCannot load libcudarN   z:preserved receipt does not authorize encoder-only recoveryr]   r^   canon_sha256verifiedsource_canon_sha256z(promotion/layout gate is absent or staler_   r`   ra   rb   c                    g | ]B}|                                 r|                                j        d k    3t          |          CS )r   )rF   statst_sizer   )rZ   r   s     r   
<listcomp>zmain.<locals>.<listcomp>R   sA    ___TT[[]]_diikkFY]^F^F^s4yyF^F^F^r   z(verified intro recovery inputs missing: rc   rd   z9intro v2 output/receipt already exists and requires auditformatdurationg       @gMbP?g{Gz?z1intro recovery audio duration verification failedc              3  x   K   | ]5}t          d  |                    dg           D                       dk    V  6dS )c                D    g | ]}|                     d           dk    |S 
codec_typeaudior   rZ   items     r   rt   z"main.<locals>.<genexpr>.<listcomp>`   s/    bbbT@V@VZa@a@aD@a@a@ar   streamsr   N)lenr   )rZ   infos     r   	<genexpr>zmain.<locals>.<genexpr>`   sf        `  `mqsbbTXXi%<%<bbbccghh  `  `  `  `  `  `r   z/intro recovery audio stream verification failedr+   ffmpegrM   z-yz-loop1z-iz-tz.6fz-r30z-c:vz-presetmediumz-crf18z-pix_fmtyuv420pz-c:aaacz-ar48000z-ac2z	-movflagsz
+faststart)checkr   c                D    g | ]}|                     d           dk    |S )rz   videor|   r}   s     r   rt   zmain.<locals>.<listcomp>n   .    LLLt$((<*@*@G*K*Kd*K*K*Kr   c                D    g | ]}|                     d           dk    |S ry   r|   r}   s     r   rt   zmain.<locals>.<listcomp>o   r   r   g:m?r   r   
codec_nameh264widthheight)i  i8  	completedrecovery_modeencode_onlypreserved_failure_receipt)r   r   tts_reused_without_new_request
intro_text
input_pathinput_sha256
voice_pathvoice_sha256voice_duration_secondssilence_pathsilence_sha256silence_duration_secondsintro_full_pathintro_full_sha256zsha256 streaming 8 MiB)	audio_duration_secondsencoderoutput_pathartifact_sha256video_duration_secondsduration_delta_secondsindependent_probecompleted_athash_method)rl   ro   duration_secondsreceiptFr/   )r9   rP   PROJECT_MANIFEST	read_textr   r"   r    rF   rS   floatabsallr7   r8   rQ   runr   r   rT   r   TEXTdatetimenowtimezoneutc	isoformatrJ   printr:   )recoverypathsold_receiptfailure	promotionlayout
canon_hashrequiredmissingvoice_probesilence_probeaudio_probevoice_durationsilence_durationaudio_durationvideo_probevideo_durationr   videosaudiosro   r   r[   s                         @r   mainr   ?   s.	   j)33W3EEFFG{{344:H    ;   E nb999K||$%%55FX9Y9Y]f9f9fjrjvjv  xD  kE  kE  MQ  kQ  kQFGGGj...@@AAG{{8((,AU\^`IaIa,a,afr  {B  {F  {F  GN  PR  {S  {S  gS  gSWXXX
5!45???QQRRIZ./9979KKLLF~..J}}Z  ,,

:0F0Fd0R0RV\V`V`avVwVw  |F  WF  WFEFFF()5+?AWY^_lYmnH__X___G QOgOOPPP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[_._._NOOO  `  `  wB  DQ  S^  v_  `  `  `  `  ` N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     g''K;x0<==Nooi,,GLLwLLLFLLwLLLFN^+,,> 	1KK1	1!$V!1	11IMM,''61	1 w**++Sx1K1K-L-LMQ]]	1 1IMM,''50 7++x9CXz+:M 	$c+.>.>&Q\J]J]%^%^ 	)$	 1=d	
 	c% 2344
 7EfUSeMfFgFg 	c%.// 2@mH\A]A] 	!. 	E/233 6FveTcNdGeGe 	#$4 	3u]344 7J6RWXeRfKgKg #1YWZ[`ah[iWjWj!%.11^"%n~&E"F"F( )--h.?.CDDNNPP/!  G$ o&000	$* 1x]kx{  }B  CR  }S  yT  yT  U  U  di  j  j  j  k  k  k11ar   __main__rm   Fz: )rl   ro   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   r(   rJ   rS   r   __name__exit	Exceptionr'   r   r:   typestderrrY   r   r   <module>r      s   " " " " " "    				     



       tH~~'*88  X            L  L  L  L ^ z   jdjH%TTRUYYM_JhJhcfJhJhiix}~~~  FI  FP  	Q  	Q  	Q  	Q s   3B C&A	C!!C&