
    8j                        d dl Z d dlZd dlZd dlmZ  ed          ZdZdZdZ	edz  Z
edz  Zed	z  Z ed
          Z e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 dlZ eej                            dd                    Zd ZddZd Zd Zd Z d Z!e"dk    r e!             dS dS )    N)PathzJ/data/video-pipeline/Youtube-Video-Maker/Project/05062026-002-Dinh-Bo-Linhz,http://192.168.1.104:8018/package-audio-safezhttp://192.168.1.104:8018/probez%http://192.168.1.104:8018/blackdetectzoutput/intro/intro.mp4zoutput/main_story.mp4z output/main_story_qa_report.jsonzF/data/video-pipeline/Youtube-Video-Maker/data/outtro/outtro1_1080p.mp4z/data/video-pipeline/Youtube-Video-Maker/data/music/the_mountain-history-archive-145197/the_mountain-history-archive-145197.mp3z&output/thumbnails/thumb_16x9_final.pngz&output/thumbnails/thumb_9x16_final.pngzoutput/finalzfinal_video.mp4zfinal_video_probe.jsonzfinal_package_report.jsonzfinal_blackdetect.jsonz'logs/step18_final_package_manifest.json
BGM_VOLUMEz0.20c                 R    t          t          j        d          | z   d           d S )Nz%Y-%m-%d %H:%M:%S T)flush)printtimestrftime)msgs    $scripts_run_step_18_final_package.pylogr      s+    	$-,
-
-
34@@@@@@    `T  c                    t           j                            | t          j        |d                              d          ddid          }t           j                            ||          5 }t          j        |                                	                    d                    cd d d            S # 1 swxY w Y   d S )	NFensure_asciiutf-8zContent-Typezapplication/jsonPOST)dataheadersmethodtimeout)
urllibrequestRequestjsondumpsencodeurlopenloadsreaddecode)urlpayloadr   reqrs        r   	post_jsonr'      s    
.
 
 4:gE+R+R+R+Y+YZa+b+bm{  }O  mP  Y_
   `  `C			W		5	5 4z!&&((//'22334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s   .9B44B8;B8c                 r    t          |                     di                               d          pd          S )Nformatdurationr   )floatget)probes    r   r*   r*   #   s1    8R((,,Z88=A>>>r   c                 b    t          fd|                     dg           D                       S )Nc              3   J   K   | ]}|                     d           k    V  dS )
codec_typeN)r,   ).0styps     r   	<genexpr>zhas_stream.<locals>.<genexpr>'   s4      LLaquu\""c)LLLLLLr   streams)anyr,   )r-   r3   s    `r   
has_streamr7   &   s4    LLLL599Y3K3KLLLLLLr   c                 R    t          j        |                     d                    S )Nr   encoding)r   r    	read_text)paths    r   	load_jsonr=   )   s     :dnngn66777r   c                  V   t                               dd           t          j                            dd           t          t
          t          t          t          t          t          g} d | D             }|r&t          dt          j        |d          z             t          t                    }|                    d          st!          d           t#          t$          d	t'          t                    id
          t#          t$          d	t'          t
                    id
          t#          t$          d	t'          t                    id
          d}|                                D ]7\  }}t+          |d          rt+          |d          st          | d          8t!          d           t'          t                    t'          t
                    t'          t                    t'          t                    t'          t,                    ddt.          ddd
}t#          t0          |d          }|                    d          p*t#          t$          d	t'          t,                    id
          }t2                              t          j        |dd          d           t7          d |                                D                       }	t;          |          }
|
|	z
  }t!          d           t#          t<          t'          t,                    t'          t           dz            dd          }t>                              t          j        |dd          d           t,                                           o!t,          !                                j"        d k    t+          |d          t+          |d          tG          |                    d                    g d!|	|
|tI          |          d"k    t.          |                    d#          |                    d#d$          d$k    d%}tK          |d&         |d'         |d(         |d)         |d*         |d+         g          }tL          j'        d,|rd-nd.t'          t                    t'          t
                    t'          t                    t'          t                    t'          t                    t'          t                    t'          t                    d/t'          t,                    t'          t2                    t'          t>                    ||||d0gd1}tP                              t          j        |dd          d           t                              t          j        tL          j'        d,|d2         t'          t,                    t'          tP                    |
t.          d3dd          d           |st!          d4           t!          d5t          j        |d2         |
t.          d6d          z              d S )7NT)parentsexist_okc                 T    g | ]%}|                                 t          |          &S  )existsstrr1   ps     r   
<listcomp>zmain.<locals>.<listcomp>0   s+    :::!qxxzz:s1vv:::r   zmissing_input Fr   passedzQWARN main_story QA needs review; continuing package because user will QA manually
input_pathx   r   )intromainoutrovideoaudio_missing_audio_or_videoz%PACKAGE intro + main + outro with BGMi]        veryfast)
intro_video_pathmain_video_pathoutro_video_pathbgm_audio_pathoutput_video_pathsample_ratechannels
bgm_volumecrfpresetr   r-      )r   indentr   r9   c              3   4   K   | ]}t          |          V  d S )N)r*   rE   s     r   r4   zmain.<locals>.<genexpr>N   s(      GGAHQKKGGGGGGr   zBLACKDETECT finalzfinal_blackdetect.log)rI   log_pathi  )rK   
main_storyrM   g      ?event_countr   )final_exists	has_audio	has_videomain_qa_passedorderexpected_duration_secfinal_duration_secduration_diff_secduration_within_tolerancer[   black_event_countblackdetect_clearrd   re   rf   rg   rl   rn      	completedneeds_review)rT   rU   main_qa_report_pathrV   rW   thumbnail_16x9_paththumbnail_9x16_pathz]Step 18 package is not final approval; run Step 19 final QA before output/info.json approval.)
project_idstepstatusinputsrX   
probe_pathblackdetect_pathpackage_responseinput_probesfinal_probe
validationnotesrw   )ru   rv   rw   rX   report_pathduration_secr[   zIWARN final package needs review; continuing because user will QA manuallyzDONE )rw   r*   r[   ))OUT_DIRmkdirMANIFESTparentINTROMAINMAIN_QAOUTROBGMTHUMB_16THUMB_9
SystemExitr   r   r=   r,   r   r'   PROBE_ENDPOINTrD   itemsr7   FINALr   PACKAGE_ENDPOINT
PROBE_JSON
write_textsumvaluesr*   BLACKDETECT_ENDPOINT
BLACK_JSONrC   statst_sizeboolabsallPROJECTnameREPORT_JSON)requiredmissingmain_qar|   r   prr$   r{   r}   expected_durationfinal_durationduration_diffblackr~   rH   reports                   r   rL   rL   ,   s   MM$M...O$666tWeS(GDH::x:::G U)DJwU,S,S,SSTTT  G;;x   a_```>L#e**+EsSSS.<T*CSQQQ>L#e**+EsSSS L
 !&&(( ? ?b"g&& 	?jW.E.E 	?===>>>	?/000JJt99JJc(( ZZ  G !!17EJJJ"&&w//u9^l\_`e\f\fMgqt3u3u3uK$*[uQOOOZabbbGG1D1D1F1FGGGGGk**N"%66M*3u::SVW^axWxSySy,z,z  EJ  K  K  KE$*UqIIIT[\\\F5::<<+?$+FW55W55w{{84455111!2,*%(%7%73%> "YY}55"YY}a88A= J >"J{$;Z=T#$j1L&MzZmOn  F
 l!';++^ #E

"4yy#&w<< #E

!#hh#&x==#&w<<
 
 !ZZ*oo
OO,$" qr) F, 4:f5KKKV]^^^
',rTZ[cTdz}  D  {E  {E  UX  Yd  Ue  Ue  vD  S]  $^  $^  mr  {|  }  }  }  HO  P  P  P YWXXX$*x(8ndnoo  D  E  E  E  	E  F  F  F  F  Fr   __main__)r   )#r   r   urllib.requestr   pathlibr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   osr+   environr,   r   r   r'   r*   r7   r=   rL   __name__rB   r   r   <module>r      s              
$[
\
\A 2> **((
6
6UVV
d  M  N  N==
<
<
N
"##//
33//
>> 				U2:>>,7788
A A A4 4 4 4
? ? ?M M M8 8 8TF TF TFj zDFFFFF r   