
    @j                         d dl Z d dlZd dlZd dlmZ  ed          ZdZedz  Zedz  Z	edz  Z
edz  Zed	z  ed
z  edz  gZd Zd Zd Zd Zedk    r e             dS dS )    N)PathzF/data/video-pipeline/Youtube-Video-Maker/Project/11062026-002-Nha-Dinhzhttp://192.168.1.104:8002/probezaudio/master_narration.wavz$audio/master_narration_timeline.jsonzaudio/master_audio_probe.jsonz$logs/step9_probe_audio_manifest.jsonzaudio/render_parts/part_*.wavzaudio/parts/part_*.wavzaudio/part_*.wavc                 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_09_probe_audio.pylogr      s+    	$-,
-
-
34@@@@@@    c                 2   t           j                            t          t	          j        dt          |           i                              d          ddid          }t           j                            |d          5 }t	          j	        |
                                                    d                    }d d d            n# 1 swxY w Y   |                    d	i           }t          d
 |                    dg           D             i           }t          |           t          |                    d          p|                    d          pd          t          |                    d          pd          |                    d          |                    d          |                    d          t          |                    d          p|                    d          pd          t          |                    d          pd          |d	S )N
input_pathutf-8zContent-Typezapplication/jsonPOST)dataheadersmethodi,  )timeoutformatc              3   L   K   | ]}|                     d           dk    |V   dS )
codec_typeaudioN)get).0ss     r
   	<genexpr>zprobe.<locals>.<genexpr>"   s9      ]]qaeeL>Q>QU\>\>\>\>\>\>\]]r   streamsdurationr   sample_ratechannels
codec_nameformat_namebit_ratesize)	
audio_pathduration_secr   r    r!   r"   r#   
size_bytes	raw_probe)urllibrequestRequestENDPOINTjsondumpsstrencodeurlopenloadsreaddecoder   nextfloatint)pathreqresprawfmtaudio_streams         r
   prober>      s
   
.
 
 Zs4yy12299'BB!34	 !  C 
		S		1	1 6Tj++G44556 6 6 6 6 6 6 6 6 6 6 6 6 6 6
''(B

C]]CGGIr$:$:]]]_abbL$iicggj11V\5E5Ej5Q5QVUVWW<++M::?a@@ $$Z00"&&|44ww}--
++P|/?/?
/K/KPqQQ#''&//.Q//
 
 
s    :CC
C
c                     | j         S )N)stem)r8   s    r
   part_idrA   0   s
    9r   c                     t                                           st          dt                      d } d }t                                          rVt	          j        t                              d                    }|                    d          } t          t                    }t          dt                       t          t                     }g }t          D ]A}|                    t          |j                            |j                                       Bt#                      }g }|D ]0}||vr*|                    |           |                    |           1g }	|D ]J}t          d|            t          |          }
t)          |          |
d<   |	                    |
           Kg }d }| [|d         t+          |           z
  }t-          |          d	k    r|                    d
|dd           n|                    d           |	s|                    d           t.          j        dt0          dt          t                     |d         ||| ||	|d}t2                              t	          j        |dd          d           t.          j        ddt0          t          t2                    t          t                     |d         t9          |	          |d	}t:          j                            dd           t:                              t	          j        |dd          d           t          dt	          j        d|d         t9          |	          dd          z              d S )NzMissing master audio: r   )encodingtotal_durationzPROBE master zPROBE part rA   r&   g{Gz?z6Master probe duration differs from Step 8 timeline by z.3fz)s; use probe duration as source of truth.z;Master probe duration matches Step 8 timeline within 0.01s.z=No part_XX.wav files found yet; only master audio was probed.	   worker_probe_duration)
project_idstependpointsource_of_truthmaster_audio_pathmaster_duration_secmaster_probetimeline_pathtimeline_expected_duration_sectimeline_vs_probe_diff_secpartsnotesF   )ensure_asciiindent	completed)	rG   rH   statusrI   output_probe_jsonrK   rL   parts_countrR   T)parentsexist_okzDONE )rW   rL   rQ   )rT   )MASTER_AUDIOexists
SystemExitTIMELINEr-   r2   	read_textr   r/   r   r>   
PART_GLOBSextendsortedparentglobnamesetaddappendrA   r6   absPROJECTr,   OUTPUT
write_textr.   lenMANIFESTmkdir)timeline_expectedrN   timeline_docmasterparts_pathspatternseenunique_partsprQ   inforR   diffresultmanifests                  r
   mainr}   4   s      B@,@@AAAM &z("4"4g"4"F"FGG(,,-=>>H&&&'''<  FK F F6'."5"5gl"C"CDDEEEE55DL # #D==HHQKKK"""E  !Qxx!!**YTED$n%.?(@(@@t99tLL  FRV  F  F  F  F  G  G  G  GLLVWWW VTUUU l2 ..%n5&*;&* F djeAFFFQXYYY l [[ ..%n55zz
 
H O$666
8%JJJU\]]]$*FSaLbmpqvmwmwxx  HM  N  N  N  	N  O  O  O  O  Or   __main__)r-   r   urllib.requestr)   pathlibr   rk   r,   r\   r_   rl   ro   ra   r   r>   rA   r}   __name__ r   r
   <module>r      s              
$W
X
X,55;;	2	2;;--&&  
A A A  0  GO GO GOT zDFFFFF r   