
    %h                        S SK r S SKrS SKrS SKrS SKrS SKrS SKr S SKJr  \R                  R                  \R                  S    5      R                  SSS5      r\" \R"                  S\R"                  5      r\" \R&                  S\R&                  5      r\\S.r \r\R2                  " \5      rS rS	 r     SS
 jrS rSS jr SS jr!g! \	 a	    S SK
Jr   Nf = f! \ a     NJf = f)    N)MutableSequence-    bufferinputoutputc                     U $ )zZ
Used when we didn't explicitly specify a stream to avoid using
codecs.get{reader,writer}
 )streams    G/var/www/auris/envauris/lib/python3.13/site-packages/srt_tools/utils.pynoopr      s	    
 M    c                 $    U S:X  a	  [         U   $ U $ )Nr   )DASH_STREAM_MAP)argarg_types     r   dash_to_streamr   '   s    
czx((Jr   c           
      0   / nUbj  UR                  S5        UR                  5        HE  u  pgUR                  SR                  U5      5        UR                  SR                  U5      5        MG     [        R                  " [
        U SR                  U5      [        R                  S9nU(       a  UR                  SSSS	S
 SSS9  OUR                  SSS[        S SS9  U(       d2  UR                  SSS[        S SS9  U(       d  UR                  SSSSS9  Sn	U(       a  [        R                  n	UR                  SSSU	S9  UR                  SS S![        R                  [        R                  S"S#9  UR                  S$S%SS&S9  UR                  S'S(S)S*9  U$ )+Nz	examples:z  {}z	    $ {}

)progdescriptionepilogformatter_classz--inputz-iFILEappendc                     [        U S5      $ Nr	   r   r   s    r   <lambda>basic_parser.<locals>.<lambda>M       ^C9r   zthe files to processT)metavaractiontypehelprequiredc                     [        U S5      $ r   r    r!   s    r   r"   r#   W   r$   r   z$the file to process (default: stdin))r%   defaultr'   r(   z--outputz-oc                     [        U S5      $ )Nr
   r    r!   s    r   r"   r#   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&   r0   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_parserrK   -   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                    [        U SS 5      (       aU  U R                  [        S   :X  a  [        S5      eU R                  [        S   :w  a  [        S5      eU R                  U l        S GH  n[
        R                  SU5         [        X5      nU R                  =(       d    SnU R                  =(       d    S	n[        R                  " U5      n[        R                  " U5      n[
        R                  S
U5        U[        R                  5       ;   a  [
        R                  SU5        X R                  L aE  [        R                  " U" U R                  5      R                  5       U R                   S9U l        GM  X R                  L a  U" U R                  5      U l        GM;  GM>  [
        R                  SU5        X R                  L GaS  [#        U R                  [$        5      (       a  ['        U R                  5       H  u  pxU[        R                  5       ;   aR  X R                  L aB  [        R                  " U" U5      R                  5       U R                   S9U R                  U'   Mm  Mo  U" [)        US5      5      n	U	   [        R                  " U	R                  5       U R                   S9U R                  U'   S S S 5        M     GMd  U" [)        US5      5      n	U	   [        R                  " U	R                  5       U R                   S9U l        S S S 5        GM  U" [)        U R                  S5      5      U l        GM     g ! [         a     GM  f = f! , (       d  f       GMh  = f! , (       d  f       GM  = f)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_argsrk      s   tY%%::11<==;;/(33<==jj*		*K8	T/F 41'  /  0		$f- _++--II-{;# YY$**%**,D<V<V
 ;;& $DKK0	 ' II1;?#djj/::'0'<#'='='??%303		$)(O$8$8$:262L2L1"

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

1 "# (= d6401A%(YYFFHD4N4N&
 
 $Dd$;<s +
  		R "# s*   M;M"3M,
MM
M),
M<	c                      [         R                  " X[        R                  SS9$ ! [         R                   a  n[
        R                  S5        e S nAff = f)NT)r/   eolin_placezLParsing failed, maybe you need to pass a different encoding with --encoding?)r[   composeoslinesepSRTParseErrorrS   critical)subsr/   
thrown_excs      r   compose_suggest_on_failrv      sJ    {{4BJJNN 	
 	s   #& AAAc              #   $  #    [        U 5      n[        [        R                  " X15      5      nU(       d  [	        U5      U:w  a  gUv   U H  nUSS U4-   nUv   M     U(       a*  [        [	        U5      5       H  nUS:w  d  M  XFS v   M     gg7f)zQ
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##H45FV-
Ltg%  V%CaxTl" & s   A>BB)NFFNF)T)   T)"r6   rW   r[   r?   sysrz   rp   collections.abcr   ImportErrorcollectionspathbasenameargvreplacer8   rQ   stdinr<   stdoutr=   r   xranger}   	NameError	getLogger__name__rS   r   r   rK   rk   rv   r   r   r   r   <module>r      s     
  
  	,/ GGSXXa[)11#sA>	399h		: CJJ#**= ,8IJ	E ! WtD=N	#[  ,+,  		s#   C C# C C #C,+C,