
    i
                     `    d dl Z d dlZd dlZd dlmZ d dlmZ  e       Zd	dedede	fdZ
d
dZy)    N)Console)get_ffprobe_path	file_path	file_typereturnc                    t               ddddd| g}t        j                  |t        j                  t        j                  d      5 }|j	                         \  }}|j
                  dk7  r"t        j                  d	|        	 d
d
d
       y
t        j                  |      }	 t        |d   d         cd
d
d
       S # t        $ r Y d
d
d
       yw xY w# 1 sw Y   y
xY w)z2Get the duration of a media file (video or audio).z-verrorz-show_formatz-print_formatjsonT)stdoutstderrtextr   zError get_video_duration: Nformatduration   )r   
subprocessPopenPIPEcommunicate
returncodeloggingr	   r
   loadsfloat	Exception)r   r   ffprobe_cmdprocr   r   probe_results          g/home/nidran/Documenti/script/streaming-community/StreamingCommunity/core/processors/helper/ex_audio.pyget_video_durationr      s    #%tWnoW]_hiK			+joojoo\`	a ei))+??aMM6vh?@  zz&)	h/
;<   	 	 s0   <CC"B<<	CCCCCc                    t        | d      }t        |d      }||t        j                  d       y|t        j                  d       ddd|fS |t        j                  d	       dd|dfS t        ||z
        }||k  rd
|||fS d|||fS )aK  
    Check if the duration of the video and audio matches.

    Returns:
        - tuple: (bool, float, float, float) -> 
            - Bool: True if the duration of the video and audio matches within tolerance
            - Float: Difference in duration
            - Float: Video duration
            - Float: Audio duration
    video)r   audioz][yellow]Warning: Both video and audio durations are None. Returning 0 as duration difference.)F        r"   r"   zN[yellow]Warning: Video duration is None. Using audio duration for calculation.Fr"   zN[yellow]Warning: Audio duration is None. Using video duration for calculation.T)r   consoleprintabs)
video_path
audio_path	tolerancevideo_durationaudio_durationduration_differences         r   check_duration_v_ar,   (   s     (
gFN'
gFN ."8uv#		fgc3..		fgc>3.. n~=> i'(..HH)>>II    )file)g      ?)r
   r   r   rich.consoler   StreamingCommunity.setupr   r#   strr   r   r,    r-   r   <module>r3      sC       ! 6 )# # 5 ("Jr-   