o
    p1h                     @   s  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zd dlmZ W n e	y3   d dl
mZ Y nw ejejd  dddZeejdejZeejdejZeedZzeZW n	 eyd   Y nw eeZdd	 Zd
d Z					dddZdd ZdddZ dddZ!dS )    N)MutableSequence-    bufferinputoutputc                 C   s   | S )zf
    Used when we didn't explicitly specify a stream to avoid using
    codecs.get{reader,writer}
     )streamr
   r
   c/var/www/html/alexa/alex_system/speach-to-text/venv/lib/python3.10/site-packages/srt_tools/utils.pynoop   s   r   c                 C   s   | dkrt | S | S )Nr   )DASH_STREAM_MAP)argarg_typer
   r
   r   dash_to_stream'   s   r   Fc           
   	   C   s2  g }|d ur$| d | D ]\}}| d| | d| qtjt| d|tjd}|rB|jdddd	d
d ddd n|jdddt	dd dd |si|jdddt
dd dd |si|jddddd d}	|rptj}	|jddd|	d |jd d!d"tjtjd#d$ |jd%d&dd'd |jd(d)d*d+ |S ),Nz	examples:z  {}z	    $ {}

)progdescriptionepilogformatter_classz--inputz-iFILEappendc                 S   
   t | dS Nr   r   r   r
   r
   r   <lambda>M      
 zbasic_parser.<locals>.<lambda>zthe files to processT)metavaractiontypehelprequiredc                 S   r   r   r   r   r
   r
   r   r   W   r   z$the file to process (default: stdin))r   defaultr!   r"   z--outputz-oc                 S   r   )Nr	   r   r   r
   r
   r   r   a   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shelpr
   r
   r   basic_parser-   s   


		rC   c           
   
   C   s   t | dd r | jtd krtd| jtd krtd| j| _dD ]}td| zt | |}W n	 ty:   Y q"w | jp?d}| jpDd	}t	
|}t	|}td
| |t v rtd| || ju rutj|| j | jd| _q"|| ju r|| j| _q"td| || ju rt| jtrt| jD ]E\}}|t v r|| ju rtj|| | jd| j|< q|t|d}	|	 tj|	 | jd| j|< W d    n1 sw   Y  qq"|t|d}	|	 tj|	 | jd| _W d    n1 sw   Y  q"|t| jd| _q"d S )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fr
   r
   r   set_basic_args   sn   











rb   Tc              
   C   s>   zt j| |tjddW S  t jy } ztd  d }~ww )NT)r'   eolin_placezLParsing failed, maybe you need to pass a different encoding with --encoding?)rR   composeoslinesepSRTParseErrorrJ   critical)subsr'   
thrown_excr
   r
   r   compose_suggest_on_fail   s   rl      c                 c   s    t | }tt||}|st||krdS |V  |D ]}|dd |f }|V  q|rAtt|D ]}|dkr@||d V  q3dS dS )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idxr
   r
   r   sliding_window   s    r{   )NFFNF)T)rm   T)"r.   rN   rR   r7   sysrp   rf   collections.abcr   ImportErrorcollectionspathbasenameargvreplacer0   rH   stdinr4   stdoutr5   r   xrangers   	NameError	getLogger__name__rJ   r   r   rC   rb   rl   r{   r
   r
   r
   r   <module>   sB   


Z
G