
    ᨽg                     l    d dl Z d dlZd dlZddlmZ  G d dej
                        Zd Zd
dZd Z	d	 Z
y)    N   )loggerc                   :    e Zd ZdZd Zd Zed        ZddZd Z	y)	
LogCatcherzThread to keep reading from stderr so that the buffer does not
    fill up and stalls the ffmpeg process. On stderr a message is send
    on every few frames with some meta information. We only keep the
    last ones.
    c                     || _         d| _        g | _        d| _        t        j
                  j                  |        d| _        d| _        | j                          y )N     TF)
_file_header_lines
_remainder	threadingThread__init__daemon_should_stopstart)selffiles     `/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/imageio_ffmpeg/_parsing.pyr   zLogCatcher.__init__   sJ    
!!$'!

r	   c                     d| _         y )NT)r   r   s    r   stop_mezLogCatcher.stop_me   s
     r	   c                     | j                   S )z>Get header text. Empty string if the header is not yet parsed.)r   r   s    r   headerzLogCatcher.header   s     ||r	   c                 |   |dkD  r{t        j                          |z   }| j                         rTt        j                          |k  r=t        j                  d       | j                         rt        j                          |k  r=dj                  | j                        }| j
                  dz   |j                  dd      z   S )aG  Get the whole text written to stderr so far. To preserve
        memory, only the last 50 to 100 frames are kept.

        If a timeout is given, wait for this thread to finish. When
        something goes wrong, we stop ffmpeg and want a full report of
        stderr, but this thread might need a tiny bit more time.
        r   g{Gz?   

utf-8ignore)timeis_alivesleepjoinr   r   decode)r   timeoutetimeliness       r   get_textzLogCatcher.get_text!   s     Q;IIK')E--/diikE&9

4  --/diikE&9 

4;;'||d"U\\'8%DDDr	   c                    t         }| j                  sAt        j                  d       	 | j                  j                  d      }|sn|j                  dd      j                  dd      }|j                  d      }| j                  |d   z   |d<   |j                  d      | _	        | j                  j                  |       | j                  sVt        | j                        rddj                  | j                        }| xj                  |j!                  dd      z  c_        n#| j                  r || j                        | _        | j                  sA	 | j                  j#                          y # t        $ r Y 'w xY w# t$        $ r Y y w xY w)	Nr         r   s   

r   r    )limit_linesr   r!   r#   r
   read
ValueErrorreplacesplitr   popr   extendr   get_output_video_liner$   r%   close	Exception)r   limit_lines_localliner(   r   s        r   runzLogCatcher.run3   s9   '##JJqMzzr* <<u-55guEDJJu%Eq1E!H#iimDOKKu%<<(5"ZZ4FLLFMM'8$DDL/<+ ##2	JJ+  ,  		s#   E1 F  1	E=<E= 	FFN)r   )
__name__
__module____qualname____doc__r   r   propertyr   r)   r:    r	   r   r   r      s0    !  E$ r	   r   c                     d}| D ]C  }|j                         }|j                  d      rd}'|s*|j                  d      s<d|v sA|c S  y)z[Get the line that defines the video stream that ffmpeg outputs,
    and which we read.
    Fs   Output Ts   Stream s    Video:N)lstrip
startswith)r(   	in_outputr9   slines       r   r5   r5   V   sS     I J'I
+
e0Cr	   c                 <    t        |       d|z  kD  r
dg| | d z   } | S )z(When number of lines > 2*N, reduce to N.   s#   ... showing only last few lines ...N)len)r(   Ns     r   r.   r.   d   s,    
5zAE785!:ELr	   c                     t        |       dk(  rt        | d         S t        |       dk(  r dt        | d         z  t        | d         z   S t        |       dk(  r2dt        | d         z  dt        | d         z  z   t        | d         z   S y)zZconverts a time to second. Either cvsecs(min, secs) or
    cvsecs(hours, mins, secs).
    r   r   rG   <      i  N)rH   float)argss    r   cvsecsrO   k   s     4yA~T!W~	TaE$q'N"U47^33	TaeDGn$rE$q'N'::U47^KK 
r	   c                    | j                         }i }|d   j                  dd      d   j                  d      d   }|j                         dz   |d   j                         z   |d<   |D cg c])  }|j                         j	                  d      s#d	|v s(|+ }}|d   }|j                  d
d      d   j                         j                  dd      d   j                         |d<   t        j                  d|j                  d
d      d         d   j                         |d<   |D cg c])  }|j                         j	                  d      s#d|v s(|+ }}t        |      dkD  rL|d   }|j                  dd      d   j                         j                  dd      d   j                         |d<   d}	|d   fD ]:  }t        j                  d|      }
|
st        |
d   d   j                               }	< |	|d<   |d   }t        j                  d|      }||j                         |j                         dz
   j                  d      }t        t        t        |            |d<   |d   }t        j                  d|      }||j                         |j                         dz
   j                  d      }t        t        t        |            |d<   |d   |d   k7  r+t        j                   dj#                  |d   |d                t        j$                  d      }|j                  |       }d}||j'                         d   }t        |      |d<   |D cg c]	  }d|v s| c}d   }t        j                  d|      }d}|;||j                         dz   |j                          j                  d      }t)        | }||d<   |S c c}w c c}w c c}w )Nr   versionr   r-   	Copyright ffmpeg_versionzStream z Video: zVideo: codecz,\s*(?![^()]*\))pix_fmtz Audio: zAudio: audio_codecz ([0-9]+\.?[0-9]*) (fps)fpsz [0-9]*x[0-9]*(,| )xsource_sizesizezIThe frame size for reading {} is different from the source frame size {}.zrotate\s+:\s([0-9]+)rotatez
Duration: z, [0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]:duration)
splitlinesr2   striprB   rC   rerH   findallrM   searchr   endtuplemapintr   warningformatcompilegroupsrO   )textr(   metaverl
videolinesr9   
audiolines
audio_linerX   matchesmatchparts
reo_rotater\   r^   hmss                    r   parse_ffmpeg_headerrx   w   s   OOED
 (..A
&r
*
0
0
=a
@C YY[3.q1AAD	 AHHJ11)<qJ 
 a=DJJy!,R0779??QGJPPRDMhh 	

9a $	 		 
 	O AHHJ11)<qJ  :]
Y*2.557==c1EaHNNP 	] CA /**8$?
1++-.C/ DK a=DII+T2Eq177<EC0D b>DII+T2Eq177<ES%)DL Md6l*77=vVd=18	
 34Jd#EF"[DN 2! 1A215DIIDdKEH5;;=1$uyy{399#>3<DK]&f 3s0   +$OOO($O
O
O
	OO)    )ra   r   r!   _utilsr   r   r   r5   r.   rO   rx   r@   r	   r   <module>r{      s<    	   K!! K\	LYr	   