
    w;3h                        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j                  j                  ej                  d          j                  ddd      Z eej"                  dej"                        Z eej&                  dej&                        ZeedZ	 eZ ej2                  e      Zd Zd	 Z	 	 	 	 	 dd
Zd ZddZ ddZ!y# e	$ r	 d dl
mZ Y w xY w# e$ r Y Ew xY w)    N)MutableSequence-    bufferinputoutputc                     | S )zf
    Used when we didn't explicitly specify a stream to avoid using
    codecs.get{reader,writer}
     )streams    O/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/srt_tools/utils.pynoopr      s	    
 M    c                 "    | dk(  r	t         |   S | S )Nr   )DASH_STREAM_MAP)argarg_types     r   dash_to_streamr   '   s    
czx((Jr   c           	      8   g }|i|j                  d       |j                         D ]E  \  }}|j                  dj                  |             |j                  dj                  |             G t        j                  t
        | dj                  |      t        j                        }|r|j                  dddd	d
 dd       n|j                  dddt        d d       |s3|j                  dddt        d d       |s|j                  dddd       d}	|rt        j                  }	|j                  ddd|	       |j                  dd d!t        j                  t        j                  d"#       |j                  d$d%dd&       |j                  d'd(d)*       |S )+Nz	examples:z  {}z	    $ {}

)progdescriptionepilogformatter_classz--inputz-iFILEappendc                     t        | d      S Nr	   r   r   s    r   <lambda>zbasic_parser.<locals>.<lambda>M       ^C9 r   zthe files to processT)metavaractiontypehelprequiredc                     t        | d      S r   r    r!   s    r   r"   zbasic_parser.<locals>.<lambda>W   r#   r   z$the file to process (default: stdin))r$   defaultr&   r'   z--outputz-oc                     t        | d      S )Nr
   r    r!   s    r   r"   zbasic_parser.<locals>.<lambda>a   s    ^C: r   z&the file to write to (default: stdout)z	--inplacez-p
store_truezmodify file in place)r%   r'   z:allow blank lines in output, your media player may explodez--no-strictstore_falsestrict)r%   destr'   z--debugstore_const	log_levelzenable debug logging)r%   r/   constr*   r'   z--ignore-parsing-errorsz-cz3try to keep going, even if there are parsing errorsz
--encodingz-ez3the encoding to read/write files in (default: utf8))r'   )r   itemsformatargparseArgumentParser	PROG_NAMEjoinRawDescriptionHelpFormatteradd_argumentSTDIN_BYTESTREAMSTDOUT_BYTESTREAMSUPPRESSloggingDEBUGINFO)
r   multi_input	no_outputexampleshide_no_strictexample_linesdesccodeparsershelps
             r   basic_parserrJ   -   s    M[)"..* 	<JD$  t!45  !4!4T!:;	< $$yy' <<	F 9' 	 	
 	$97 	 	
 %:9 	 	
 #+	    IE!!
m(QVW
mm#   !B	   d!V   Mr   c                    t        | dd       rS| j                  t        d   k(  rt        d      | j                  t        d   k7  rt        d      | j                  | _        dD ]  }t
        j                  d|       	 t        | |      }| j                  xs d}| j                  xs d	}t        j                  |      }t        j                  |      }t
        j                  d
|       |t        j                         v rt
        j                  d|       || j                  u rFt        j                   || j                        j                         | j                         | _        || j                  u s || j                        | _        0t
        j                  d|       || j                  u rMt#        | j                  t$              rt'        | j                        D ]  \  }}|t        j                         v rR|| j                  u s+t        j                   ||      j                         | j                         | j                  |<   n |t)        |d            }	|	5  t        j                  |	j                         | j                         | j                  |<   d d d         O |t)        |d            }	|	5  t        j                  |	j                         | j                         | _        d d d         |t)        | j                  d            | _         y # t        $ r Y w xY w# 1 sw Y   ]xY w# 1 sw Y   xY w)Ninplacer	   zCannot use --inplace on stdinr
   zCannot use -o and -p togetherr   zProcessing stream "%s"z	utf-8-sigzutf-8zGot %r as streamz%s in DASH_STREAM_MAP)ignore_errorsz%s not in DASH_STREAM_MAPrbwb)getattrr	   r   
ValueErrorr
   logdebugAttributeErrorencodingcodecs	getreader	getwritervaluessrtparsereadignore_parsing_errors
isinstancer   	enumerateopen)
argsstream_namer   read_encodingwrite_encodingr_encw_enciinput_fnfs
             r   set_basic_argsrj      s   tY%::11<==;;/(33<==jj* 9=		*K8	T;/F 41'  /  0		$f- _++--II-{;# YY$**%**,D<V<V
 4;;& $DKK0II1;?#djj/:'0'< "8#'='='??%303		$)(O$8$8$:262L2L1"

1
 !&d8T&: ;A!" "03		$%FFHD<V<V1"

1" "" d6401A %(YYFFHD4N4N&
 
 $Dd$;<s9=
  		R" " s*   >L*)=L:5M*	L76L7:MM	c                     	 t        j                  | |t        j                  d      S # t         j                  $ r}t
        j                  d        d }~ww xY w)NT)r.   eolin_placezLParsing failed, maybe you need to pass a different encoding with --encoding?)rZ   composeoslinesepSRTParseErrorrR   critical)subsr.   
thrown_excs      r   compose_suggest_on_failru      sL    {{4BJJNN 	
 	s   &) AAAc              #     K   t        |       }t        t        j                  ||            }|st	        |      |k7  ry| |D ]  }|dd |fz   }|  |r't        t	        |            D ]  }|dk7  s	||d   yyw)z]
    If inclusive is True, we also include final elements where len(sliced) <
    width.
    Nr   r   )itertuple	itertoolsislicelenrange)seqwidth	inclusiveseq_iterslicedelemidxs          r   sliding_windowr      s     
 CyH 9##He45FV-
L tg% V% 	#CaxSTl"	# s   A2B 5B )NFFNF)T)   T)"r5   rV   rZ   r>   sysry   ro   collections.abcr   ImportErrorcollectionspathbasenameargvreplacer7   rP   stdinr;   stdoutr<   r   xranger|   	NameError	getLogger__name__rR   r   r   rJ   rj   ru   r   r   r   r   <module>r      s     
  
  	,/ GGSXXa[)11#sA>	399h		: CJJ#**= ,8IJ	E g! WtD=N	#[  ,+,  		s#   C C CCC'&C'