
    h)                     R   d dl Z d dlZd dlZ	 d dlmZ n# e$ r	 d dlmZ Y nw xY wd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ ej        dfej        d	fej        d
fej        dfej        dffZ ed eD                       Z ed eD                       Z G d dee          ZdS )    N)UserList)chain)copy)Error)
SubRipItemstr	utf_32_le	utf_32_be	utf_16_le	utf_16_beutf_8c              #   @   K   | ]\  }}|t          ||          fV  d S Nr   ).0bomcodecs      M/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/pysrt/srtfile.py	<genexpr>r      s3      CC
UE3sE??+CCCCCC    c              #   :   K   | ]\  }}t          |          V  d S r   )len)r   r   encodings      r   r   r      s,      44mc8S444444r   c                   \   e Zd ZdZdZdZdZdZddZd	 Z	d
 Z
 ee	e
          Z	 	 ddZddZd Zd Zed             Zeddefd            Zed             ZefdZeefd            ZddZddZed             Zed             Zed             Zedd            Zed             ZdS ) 
SubRipFilea  
    SubRip file descriptor.

    Provide a pure Python mapping on all metadata.

    SubRipFile(items, eol, path, encoding)

    items -> list of SubRipItem. Default to [].
    eol -> str: end of line character. Default to linesep used in opened file
        if any else to os.linesep.
    path -> str: path where file will be saved. To open an existant file see
        SubRipFile.open.
    encoding -> str: encoding used at file save. Default to utf-8.
    r         r   Nutf-8c                 ^    t          j        | |pg            || _        || _        || _        d S r   )r   __init___eolpathr   )selfitemseolr"   r   s        r   r    zSubRipFile.__init__0   s2    $,,,		 r   c                 (    | j         pt          j        S r   )r!   oslinesepr#   s    r   _get_eolzSubRipFile._get_eol6   s    y&BJ&r   c                 "    | j         p|| _         d S r   )r!   )r#   r%   s     r   _set_eolzSubRipFile._set_eol9   s    I$			r   c                 .   t          |           }rfd|j        D             |_        rfd|j        D             |_        rfd|j        D             |_        rfd|j        D             |_        t          |j                  |_        |S )aV  
        slice([starts_before][, starts_after][, ends_before][, ends_after]) -> SubRipFile clone

        All arguments are optional, and should be coercible to SubRipTime
        object.

        It reduce the set of subtitles to those that match match given time
        constraints.

        The returned set is a clone, but still contains references to original
        subtitles. So if you shift this returned set, subs contained in the
        original SubRipFile instance will be altered too.

        Example:
            >>> subs.slice(ends_after={'seconds': 20}).shift(seconds=2)
        c              3   2   K   | ]}|j         k     |V  d S r   start)r   istarts_befores     r   r   z#SubRipFile.slice.<locals>.<genexpr>T   s/      KK17]3J3J!3J3J3J3JKKr   c              3   2   K   | ]}|j         k    |V  d S r   r/   )r   r1   starts_afters     r   r   z#SubRipFile.slice.<locals>.<genexpr>V   s/      JJ17\3I3I!3I3I3I3IJJr   c              3   2   K   | ]}|j         k     |V  d S r   end)r   r1   ends_befores     r   r   z#SubRipFile.slice.<locals>.<genexpr>X   s/      GG15;3F3F!3F3F3F3FGGr   c              3   2   K   | ]}|j         k    |V  d S r   r6   )r   r1   
ends_afters     r   r   z#SubRipFile.slice.<locals>.<genexpr>Z   s/      FF15:3E3E!3E3E3E3EFFr   )r   datalist)r#   r2   r4   r8   r:   clones    ```` r   slicezSubRipFile.slice>   s    & T

 	LKKKKUZKKKEJ 	KJJJJUZJJJEJ 	HGGGGUZGGGEJ 	GFFFFUZFFFEJ%*%%
r   c                 8    |p|}|                      ||          S )aW  
        at(timestamp) -> SubRipFile clone

        timestamp argument should be coercible to SubRipFile object.

        A specialization of slice. Return all subtiles visible at the
        timestamp mark.

        Example:
            >>> subs.at((0, 0, 20, 0)).shift(seconds=2)
            >>> subs.at(seconds=20).shift(seconds=2)
        )r2   r:   )r>   )r#   	timestampkwargstimes       r   atzSubRipFile.at_   s$     "Fzzz>>>r   c                 *    | D ]} |j         |i | dS )a
  shift(hours, minutes, seconds, milliseconds, ratio)

        Shift `start` and `end` attributes of each items of file either by
        applying a ratio or by adding an offset.

        `ratio` should be either an int or a float.
        Example to convert subtitles from 23.9 fps to 25 fps:
        >>> subs.shift(ratio=25/23.9)

        All "time" arguments are optional and have a default value of 0.
        Example to delay all subs from 2 seconds and half
        >>> subs.shift(seconds=2, milliseconds=500)
        N)shift)r#   argsrA   items       r   rE   zSubRipFile.shifto   s7      	( 	(DDJ'''''	( 	(r   c                 l    |                                   t          |           D ]\  }}|dz   |_        dS )z
        clean_indexes()

        Sort subs and reset their index attribute. Should be called after
        destructive operations like split or such.
        r   N)sort	enumerateindex)r#   rK   rG   s      r   clean_indexeszSubRipFile.clean_indexes   sA     			$T?? 	# 	#KE4DJJ	# 	#r   c                 @    d                     d | D                       S )N
c              3   $   K   | ]}|j         V  d S r   )text)r   r1   s     r   r   z"SubRipFile.text.<locals>.<genexpr>   s$      ..A......r   )joinr)   s    r   rP   zSubRipFile.text   s#    yy........r    c                     |                      ||          \  }} | ||          }|                    ||           |                                 |S )z
        open([path, [encoding]])

        If you do not provide any encoding, it can be detected if the file
        contain a bit order mark, unless it is set to utf-8 as default.
        )claimed_encoding)r"   r   error_handling)_open_unicode_filereadclose)clsr"   r   rV   source_filenew_files         r   openzSubRipFile.open   sb     !$ 6 6th 6 W WX3D8444k.AAAr   c                     |                     dd          } | di |}|                    |                    d          |           |S )z
        from_string(source, **kwargs) -> SubRipFile

        `source` -> a unicode instance or at least a str instance encoded with
        `sys.getdefaultencoding()`
        rV   NTrU    )poprX   
splitlines)rZ   sourcerA   rV   r\   s        r   from_stringzSubRipFile.from_string   sR      $4d;;3====f''--nMMMr   c                     |                      |          | _        |                     |                     ||                     | S )a5  
        read(source_file, [error_handling])

        This method parse subtitles contained in `source_file` and append them
        to the current instance.

        `source_file` -> Any iterable that yield unicode strings, like a file
            opened with `codecs.open()` or an array of unicode.
        rU   )
_guess_eolr%   extendstream)r#   r[   rV   s      r   rX   zSubRipFile.read   s>     ??;//DKKNKKKLLLr   c              #     K   g }t          t          |d                    D ]\  }}|                                r|                    |           /|}g }|ryt	          |          rj	 t          j        |          V  \# t          $ rE}|xj        d	                    |          fz  c_        | 
                    |||           Y d}~d}~ww xY wdS )ao  
        stream(source_file, [error_handling])

        This method yield SubRipItem instances a soon as they have been parsed
        without storing them. It is a kind of SAX parser for .srt files.

        `source_file` -> Any iterable that yield unicode strings, like a file
            opened with `codecs.open()` or an array of unicode.

        Example:
            >>> import pysrt
            >>> import codecs
            >>> file = codecs.open('movie.srt', encoding='utf-8')
            >>> for sub in pysrt.stream(file):
            ...     sub.text += "
Hello !"
            ...     print unicode(sub)
        rN   rR   N)rJ   r   stripappendallr   
from_linesr   rF   rQ   _handle_error)rZ   r[   rV   string_bufferrK   linerb   errors           r   rg   zSubRipFile.stream   s     & $U;%=%=>> 	H 	HKE4zz|| 
H$$T****& " Hc&kk HH(3F;;;;;;  H H H

rwwv&99

))%GGGGGGGGH	H 	Hs   'A>>
C;CCc                     |p| j         }|p| j        }t          j        |d|          }|                     ||           |                                 dS )z
        save([path][, encoding][, eol])

        Use initial path if no other provided.
        Use initial encoding if no other provided.
        Use initial eol if no other provided.
        zw+r   )r%   N)r"   r   codecsr]   
write_intorY   )r#   r"   r   r%   	save_files        r   savezSubRipFile.save   s^      ty,t}KdX>>>		s+++r   c                     |p| j         }| D ]o}t          |          }|dk    r|                    d|          }|                    |           |                    d|z            s|                    |           pdS )z
        write_into(output_file [, eol])

        Serialize current state into `output_file`.

        `output_file` -> Any instance that respond to `write()`, typically a
        file object
        rN   r   N)r%   r	   replacewriteendswith)r#   output_filer%   
output_eolrG   string_reprs         r   rt   zSubRipFile.write_into   s     _DH
 
	. 
	.Dd))KT!!)11$
CCk***
 ''J77 .!!*---
	. 
	.r   c                     |                      |          }dD ]}|                    |          r|c S t          j        S )N)z
rN   )_get_first_linerz   r'   r(   )rZ   string_iterable
first_liner%   s       r   re   zSubRipFile._guess_eol   sP    ((99
' 	 	C""3'' 


zr   c                     t          |d          r|                                }	 t          t          |                    }n# t          $ r Y dS w xY wt          |d          r|                    |           |S )NtellrR   seek)hasattrr   nextiterStopIterationr   )rZ   r   previous_positionr   s       r   r   zSubRipFile._get_first_line  s    ?F++ 	7 / 4 4 6 6	d?3344JJ 	 	 	22	?F++ 	4  !2333s   A 
AAc                     t          |d          }|                    t                    }|                                 t          D ]\  }}|                    |          r|c S | j        S )Nrb)r]   rX   
BIGGER_BOMrY   BOMS
startswithDEFAULT_ENCODING)rZ   r"   file_descriptorfirst_charsr   r   s         r   _detect_encodingzSubRipFile._detect_encoding  sx    tT**%**:66! 	  	 MC%%c**    ##r   c                    |p|                      |          }t          j        |d|          }t                              |d           }|r=|                    t          |                    }||k    s|                    d           ||fS )Nrrr   r   )r   rs   r]   CODECS_BOMSgetrX   r   r   )rZ   r"   rT   r   r[   possible_bomfile_boms          r   rW   zSubRipFile._open_unicode_file"  s    #As';';D'A'Ak$h??? #x66 	$"''L(9(9::H|++  ###H$$r   c                    || j         k    r|f|j        z   |_        ||| j        k    rt          |          j        }t
          j                            d|d|d           t
          j                            |j        d                             dd                     t
          j                            d           d S d S )NzPySRT-z(line z): 
r   asciirx   rN   )	ERROR_RAISErF   	ERROR_LOGtype__name__sysstderrry   encode)rZ   rp   rV   rK   names        r   rm   zSubRipFile._handle_error/  s    S_,,UZ/EJKS]**;;'DJeeeDEEEJUZ]11'9EEFFFJT"""""	 +*r   )NNNr   )NNNNr   )NNN)r   
__module____qualname____doc__
ERROR_PASSr   r   r   r    r*   r,   propertyr%   r>   rC   rE   rL   rP   classmethodr]   rc   rX   rg   rv   rt   re   r   r   rW   rm   r_   r   r   r   r      s         JIK! ! ! !' ' '% % % (8X
&
&CGK   B? ? ? ? ( ( ("	# 	# 	# / / X/ D    [ 
 
 [
 0:     0: H H H [H@   . . . ..   [   [ 
$ 
$ [
$ 
% 
% 
% [
% # # [# # #r   r   )r'   r   rs   collectionsr   ImportError	itertoolsr   r   pysrt.srtexcr   pysrt.srtitemr   pysrt.compatr	   BOM_UTF32_LEBOM_UTF32_BEBOM_UTF16_LEBOM_UTF16_BEBOM_UTF8r   dictr   maxr   objectr   r_   r   r   <module>r      s   				 



 "$$$$$$$ " " "!!!!!!!!"                   $ $ $ $ $ $      		k*		k*		k*		k*	'"	$
 dCCdCCCCCS44t44444
]# ]# ]# ]# ]#6 ]# ]# ]# ]# ]#s    ##