
    h.                     $   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dl	Z	d dl
mZ d dlmZ ddlmZmZ ddlmZ ddlmZ dd	lmZ d dlZd
edefdZd
edefdZd
edefdZdededefdZ G d d          ZddZe dk    r e             dS dS )    N)TextIOWrapper)dedent)List   )get_file_extensionFORMAT_IDENTIFIERS)	make_time)SSAFile)VERSIONsreturnc                 ^    t          |           }|dk    st          j        | d          |S )Nr   z is not a positive number)floatargparseArgumentTypeError)r   xs     K/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/pysubs2/cli.pypositive_floatr      s5    aAq55(A)J)J)JKKKH    c                 |    	 t          j        |            | S # t          $ r t          j        d d|            w xY w)Nzunknown character encoding: )codecslookupLookupErrorr   ArgumentError)r   s    r   character_encodingr      sX    Oa O O O$T+M!+M+MNNNOs    #;c                 x    i }t          j        d|           D ]\  }}t          |          ||<   t          di |S )Nz(\d*\.?\d*)(ms|m|s|h) )refindallr   r	   )r   dvks       r   timer#   !   sH    
A
3Q77  1Qxx!>>q>>r   pathextc                 :    t          j        |           \  }}||z   S )N)opsplitext)r$   r%   base_s       r   
change_extr+   (   s    k$GD!#:r   c                   |    e Zd Zd
dZdee         defdZdee         defdZe	de
dej        ddfd	            ZdS )
Pysubs2CLIr   Nc                    t          j        t           j        dt          d          t          d                    x}| _        |                    dddd	           |                    d
dddt                      |                    ddt          dd           |                    ddt          dd           |                    dddt          d           |                    ddt          d           |                    d d!d"d#$           |                    d%d&t          d'           |                    d(d)d*d+,           |                    d-d.d/0           |                    d1d.d20           |
                                }|                    d3d4t          d5           |                    d6d4t          d7           |                    d8d9d:t          d;<           |                    d=          }|                    d>d.d?0           |                    d@d.dA0           |                    dBd.dC0           |                    dD          }|                    dEd.dF0           d S )GNpysubs2z
                                                       The pysubs2 CLI for processing subtitle files.
                                                       https://github.com/tkarabela/pysubs2
                                                       a-  
                                                       usage examples:
                                                         python -m pysubs2 --to srt *.ass
                                                         python -m pysubs2 --to srt --clean *.ass
                                                         python -m pysubs2 --to microdvd --fps 23.976 *.ass
                                                         python -m pysubs2 --shift 0.3s *.srt
                                                         python -m pysubs2 --shift 0.3s <my_file.srt >retimed_file.srt
                                                         python -m pysubs2 --shift-back 0.3s --output-dir retimed *.srt
                                                         python -m pysubs2 --transform-framerate 25 23.976 *.srt)formatter_classprogdescriptionepilogfiles*FILEzInput subtitle files. Can be in SubStation Alpha (*.ass, *.ssa), SubRip (*.srt), MicroDVD (*.sub) or other supported format. When no files are specified, pysubs2 will work as a pipe, reading from standard input and writing to standard output.)nargsmetavarhelpz-vz	--versionversionzpysubs2 )actionr:   z-fz--frominput_formatzBy default, subtitle format is detected from the file. This option can be used to skip autodetection and force specific format. Generally, it should never be needed.)choicesdestr9   z-tz--tooutput_formatz^Convert subtitle files to given format. By default, each file is saved in its original format.z--input-encENCODINGzutf-8zXCharacter encoding for input files. By default, UTF-8 is used for both input and output.)r8   defaulttyper9   z--output-enca  Character encoding for output files. By default, it is the same as input encoding. If you wish to convert between encodings, make sure --input-enc is set correctly! Otherwise, your output files will probably be corrupted. It's a good idea to back up your files or use the -o option.)r8   rB   r9   z--enc-error-handling)strictsurrogateescaperD   a  Character encoding error handling for input and output. Defaults to 'surrogateescape' which passes through unrecognized characters to output unchanged. Use 'strict' if you want the command to fail when encountering a character incompatible with selected input/output encoding.)r=   rA   r9   z--fpsFPSzThis argument specifies framerate for MicroDVD files. By default, framerate is detected from the file. Use this when framerate specification is missing or to force different framerate.z-oz--output-dirDIRzUse this to save all files to given directory. By default, every file is saved to its parent directory, ie. unless it's being saved in different subtitle format (and thus with different file extension), it overwrites the original file.)r8   r9   z--clean
store_truezAttempt to remove non-essential subtitles (eg. karaoke, SSA drawing tags), strip styling information when saving to non-SSA formats)r;   r9   z	--verbosezPrint misc loggingz--shiftTIMEz[Delay all subtitles by given time amount. Time is specified like this: '1m30s', '0.5s', ...z--shift-backz7The opposite of --shift (subtitles will appear sooner).z--transform-framerate   )FPS1FPS2z+Multiply all timestamps by FPS1/FPS2 ratio.)r7   r8   rB   r9   zoptional arguments (SRT)z--srt-keep-unknown-html-tagsz+(input) do not strip unrecognized HTML tagsz--srt-keep-html-tagszd(input) do not convert HTML tags to SubStation internally, this implies --srt-keep-unknown-html-tagsz--srt-keep-ssa-tagsz8(output) do not convert/strip SubStation tags for outputzoptional arguments (MicroDVD)z--sub-no-write-fps-declarationz7(output) omit writing FPS as first zero-length subtitle)r   ArgumentParserRawDescriptionHelpFormatterr   parseradd_argumentr   r   r   r   add_mutually_exclusive_groupr#   add_argument_group)selfrN   groupextra_srt_optionsextra_sub_optionss        r   __init__zPysubs2CLI.__init__.   s   '6xGk<ECI K; D< D< ?E Ft ?u ?u v  v  v 	v  	G3"| 	 	} 	} 	}
 	D+iI]T[I]I]^^^D(4F^"w 	 	x 	x 	x 	D&2D?"4 	 	5 	5 	5 	M:wUg"5 	 	6 	6 	6 	NJEW"L 	 	M 	M 	M
 	2<Y$5": 	 	; 	; 	; 	GU"D 	 	E 	E 	E 	D.%"D 	 	E 	E 	E 	Il"\ 	 	] 	] 	] 	K!5 	 	7 	7 	7 33559f4 } 	 	 	 	>6 Y 	 	[ 	[ 	[2!EU\j M 	 	O 	O 	O #556PQQ&&'El,Y 	' 	[ 	[ 	[&&'=l-Y 	' 	Z 	Z 	Z 	&&'<\,f 	' 	h 	h 	h #556UVV&&'GP\,e 	' 	g 	g 	g 	g 	gr   argvc                     	 |                      |          S # t          $ r t          dt          j                   Y dS w xY w)Nz
Aborted by user.)filer   )mainKeyboardInterruptprintsysstderr)rR   rW   s     r   __call__zPysubs2CLI.__call__~   sO    	99T??"  	 	 	&SZ888811	s    %A A c                 `   | j                             |          }d}|j        rt          j        t          j                   |j        r2t          j        |j                  st          j
        |j                   |j        |j        |_        i }i }|j        rd|d<   |j        rd|d<   |j        rd|d<   |j        rd|d<   t          j        d	|           t          j        d
|           |j        r|j        D ]}t          j        |          st'          d|d           |dz  }.t          j        |          st'          d|d           |dz  }Yt+          ||j        |j                  5 }t/          j        ||j        |j        fi |}d d d            n# 1 swxY w Y   |                     ||           |j        |}	|j        }
|

J d            n7t=          |j                  }t?          ||          }	|j        }
|

J d            |j        1t          j         |	          \  }}t          j!        |j        |          }	t+          |	d|j        |j                  5 } |j"        ||
|j        fd|j#         i| d d d            n# 1 swxY w Y   ntH          j%        &                                stO          tH          j%        j(        |j        |j                  }tO          tH          j)        j(        |j        |j                  }t/          j        ||j        |j                  }|                     ||           |j        p|j        }
|

J d            |"                    ||
|j        |j#                    n| j         *                                 |dz  }|dk    rdndS )Nr   )levelTkeep_unknown_html_tagskeep_html_tagskeep_ssa_tagsFwrite_fps_declarationz*Extra arguments to SSAFile.from_file(): %rz(Extra arguments to SSAFile.to_file(): %rSkippingz(does not exist)r   z(not a file))encodingerrorsz4subs.format must not be None (it was read from file)z1args.output_format must not be None (see if/else)wapply_styleszKoutput_format must not be None (it's either given or inferred at read time))rj   )+rN   
parse_argsverboseloggingbasicConfigDEBUG
output_dirr'   existsosmakedirs
output_enc	input_encsrt_keep_unknown_html_tagssrt_keep_html_tagssrt_keep_ssa_tagssub_no_write_fps_declarationdebugr4   r\   isfileopenenc_error_handlingr
   	from_filer<   fpsprocessr?   formatr   r+   splitjointo_filecleanr]   stdinisattyr   bufferstdout
print_help)rR   rW   argsrh   extra_input_argsextra_output_argsr$   infilesubsoutpathr?   r%   r*   filenameoutfiles                  r   rZ   zPysubs2CLI.main   st   {%%d++< 	5gm4444? 	)29T_#=#= 	)K(((?""nDO* 	>9=56" 	615-.! 	615o., 	?9>56BDTUUU@BSTTT: *	
 : :y :*d,>???aKFF4 :*dN;;;aKFFdT^DD[\\\ j`f&09JDHiiXhiij j j j j j j j j j j j j j j LLt,,,)1"&(,,88:p888801CDD",T3"7"7(,(:,88:m8882&(hw&7&78"$'$/8"D"DgsT_TMdeee :ip$WmTX : :X\XbTb :'8: : :: : : : : : : : : : : : : : :7:< !!## 	"39#3dnUYUlmmmF#CJ$5X\XopppG$VT->IIDLLt$$$ .=$+M ,,.{,,,LL-DJLWWWWK""$$$aKFaKKqqQ&s$   1FF 	#F 	&JJ	J	r   r   c                    |j         |                      |j                    nK|j        |                      |j                    n'|j         |j        \  }}|                     ||           |j        r|                                  d S d S )N)ms)shift
shift_backtransform_framerater   remove_miscellaneous_events)r   r   in_fpsout_fpss       r   r   zPysubs2CLI.process   s    :!JJ$*J%%%%_(JJ4?*J++++%1"6OFG$$VW555: 	/,,.....	/ 	/r   r   N)__name__
__module____qualname__rV   r   strintr_   rZ   staticmethodr
   r   	Namespacer   r   r   r   r-   r-   -   s        Ng Ng Ng Ng`T#Y 3    F'c F's F' F' F' F'P 
/g 
/X%7 
/D 
/ 
/ 
/ \
/ 
/ 
/r   r-   c                      t                      }  | t          j        dd                    }t          j        |           d S )Nr   )r-   r]   rW   exit)clirvs     r   __main__r      s5    
,,C	SXabb\		BHRLLLLLr   r   r   )!r   r   rr   r   os.pathr$   r'   ior   r]   textwrapr   typingr   formatsr   r   r#   r	   ssafiler
   commonr   rm   r   r   r   r   r   r+   r-   r   r   r   r   r   <module>r      s     				 				             



             ; ; ; ; ; ; ; ;                   c e    O# O# O O O OC C    S s s    
k/ k/ k/ k/ k/ k/ k/ k/\    zHJJJJJ r   