
    h                         d dl Z d dlZd dlmZmZmZmZmZ d dlZddl	m
Z
 ddlmZmZ  ej        ddd           G d d	                      ZdS )
    N)OptionalDictAnyClassVar	FrozenSet   )
IntOrFloat)	ms_to_str	make_timeF)repreqorderc                      e Zd ZU dZ ej        d          Zeed<   dZ	e
ed<   dZe
ed<   dZeed	<   d
Zeed<   dZe
ed<   dZeed<   dZeed<   dZe
ed<   dZe
ed<   dZe
ed<   dZeed<   dZeed<   edee         fd            Zedefd            Zej        de
ddfd            Zedefd            Zej        deddfd            Zedefd            Zedefd             Z edefd!            Z!e!j        d	eddfd"            Z!	 	 d4d#ed$ed%eded&e"e
         d'e"e#         ddfd(Z$d5d)Z%de&ee'f         fd*Z(d+d defd,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fd0Z.d+e*defd1Z/d+e*defd2Z0defd3Z1dS )6SSAEventap  
    A SubStation Event, ie. one subtitle.

    In SubStation, each subtitle consists of multiple "fields" like Start, End and Text.
    These are exposed as attributes (note that they are lowercase; see :attr:`SSAEvent.FIELDS` for a list).
    Additionaly, there are some convenience properties like :attr:`SSAEvent.plaintext` or :attr:`SSAEvent.duration`.

    This class defines an ordering with respect to (start, end) timestamps.

    .. tip :: Use :func:`pysubs2.make_time()` to get times in milliseconds.

    Example::

        >>> ev = SSAEvent(start=make_time(s=1), end=make_time(s=2.5), text="Hello World!")

    z{[^}]*}OVERRIDE_SEQUENCEr   starti'  end textFmarkedlayerDefaultstylenamemarginlmarginrmarginveffectDialoguetypereturnc                     t          j        dt                     t          d t	          j        |           D                       S )zAll fields in SSAEvent.z*Deprecated in 1.2.0 - it's a dataclass nowc              3   $   K   | ]}|j         V  d S N)r   ).0fields     P/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/pysubs2/ssaevent.py	<genexpr>z"SSAEvent.FIELDS.<locals>.<genexpr>/   s$      JJJJJJJJ    )warningswarnDeprecationWarning	frozensetdataclassesfieldsselfs    r'   FIELDSzSSAEvent.FIELDS+   s@     	BDVWWWJJ1CD1I1IJJJJJJr)   c                      | j         | j        z
  S )z
        Subtitle duration in milliseconds (read/write property).

        Writing to this property adjusts :attr:`SSAEvent.end`.
        Setting negative durations raises :exc:`ValueError`.
        )r   r   r0   s    r'   durationzSSAEvent.duration1   s     x$*$$r)   msNc                 N    |dk    r| j         |z   | _        d S t          d          )Nr   z$Subtitle duration cannot be negative)r   r   
ValueError)r1   r5   s     r'   r4   zSSAEvent.duration;   s+    77zBDHHHCDDDr)   c                     | j         dk    S )z
        When true, the subtitle is a comment, ie. not visible (read/write property).

        Setting this property is equivalent to changing
        :attr:`SSAEvent.type` to ``"Dialogue"`` or ``"Comment"``.
        Commentr    r0   s    r'   
is_commentzSSAEvent.is_commentB   s     yI%%r)   valuec                 *    |r	d| _         d S d| _         d S )Nr9   r   r:   )r1   r<   s     r'   r;   zSSAEvent.is_commentL   s      	#!DIII"DIIIr)   c                 \    ddl m} t          d  || j                  D                       S )z6Returns True if line is SSA drawing tag (ie. not text)r   )
parse_tagsc              3   *   K   | ]\  }}|j         V  d S r$   )drawing)r%   _stys      r'   r(   z&SSAEvent.is_drawing.<locals>.<genexpr>W   s(      CC61c3;CCCCCCr)   )formats.substationr?   anyr   )r1   r?   s     r'   
is_drawingzSSAEvent.is_drawingS   s?     	322222CCZZ	-B-BCCCCCCr)   c                      | j         p| j         S )z
        Returns False for SSA drawings and comment lines, True otherwise

        In general, for non-SSA formats these events should be ignored.
        )r;   rF   r0   s    r'   is_textzSSAEvent.is_textY   s     O6t77r)   c                     | j         }| j                            d|          }|                    dd          }|                    dd          }|                    dd          }|S )z
        Subtitle text as multi-line string with no tags (read/write property).

        Writing to this property replaces :attr:`SSAEvent.text` with given plain
        text. Newlines are converted to ``\N`` tags.
        r   z\h z\n
\N)r   r   subreplacer1   r   s     r'   	plaintextzSSAEvent.plaintextb   sa     y%))"d33||E3''||E4((||E4((r)   c                 <    |                     dd          | _        d S )NrK   rL   )rN   r   rO   s     r'   rP   zSSAEvent.plaintextq   s    LLu--			r)   hmsframesfpsc                 p    t          ||||||          }| xj        |z  c_        | xj        |z  c_        dS )zh
        Shift start and end times.

        See :meth:`SSAFile.shift()` for full description.

        )rR   rS   rT   r5   rU   rV   N)r   r   r   )r1   rR   rS   rT   r5   rU   rV   deltas           r'   shiftzSSAEvent.shiftu   sB     AaBv3GGG

e

Er)   c                 >    t          di |                                 S )zReturn a copy of the SSAEvent. )r   as_dictr0   s    r'   copyzSSAEvent.copy   s    ))$,,..)))r)   c                 D      fdt          j                   D             S )Nc                 F    i | ]}|j         t          |j                   S r[   )r   getattr)r%   r&   r1   s     r'   
<dictcomp>z$SSAEvent.as_dict.<locals>.<dictcomp>   s)    \\\%
GD%*55\\\r)   )r.   r/   r0   s   `r'   r\   zSSAEvent.as_dict   s)    \\\\;CUVZC[C[\\\\r)   otherc                     t          |t                    r*|                                 |                                k    S t          d          )z#Field-based equality for SSAEvents.z%Cannot compare to non-SSAEvent object)
isinstancer   r\   	TypeErrorr1   rb   s     r'   equalszSSAEvent.equals   s?    eX&& 	E<<>>U]]__44CDDDr)   c                 z    t          |t                    st          S | j        |j        k    o| j        |j        k    S r$   rd   r   NotImplementedr   r   rf   s     r'   __eq__zSSAEvent.__eq__   s7    %** 	"!!zU[(BTX-BBr)   c                 z    t          |t                    st          S | j        |j        k    p| j        |j        k    S r$   ri   rf   s     r'   __ne__zSSAEvent.__ne__   s7    %** 	"!!zU[(ADH	,AAr)   c                 v    t          |t                    st          S | j        | j        f|j        |j        fk     S r$   ri   rf   s     r'   __lt__zSSAEvent.__lt__   7    %** 	"!!
DH%ei(@@@r)   c                 v    t          |t                    st          S | j        | j        f|j        |j        fk    S r$   ri   rf   s     r'   __le__zSSAEvent.__le__   7    %** 	"!!
DH%%+uy)AAAr)   c                 v    t          |t                    st          S | j        | j        f|j        |j        fk    S r$   ri   rf   s     r'   __gt__zSSAEvent.__gt__   rp   r)   c                 v    t          |t                    st          S | j        | j        f|j        |j        fk    S r$   ri   rf   s     r'   __ge__zSSAEvent.__ge__   rs   r)   c           	      |    d| j          dt          | j                   dt          | j                   d| j        d	S )Nz<SSAEvent type=z start=z end=z text=>)r    r
   r   r   r   r0   s    r'   __repr__zSSAEvent.__repr__   sG    xxx9TZ3H3HxxyY]YaObObxxjnjsxxxxr)   )r   r   r   r   NN)r!   r   )2__name__
__module____qualname____doc__recompiler   r   __annotations__r   intr   r   strr   boolr   r   r   r   r   r   r   r    propertyr   r2   r	   r4   setterr;   rF   rH   rP   r   floatrY   r]   r   r   r\   rg   objectrk   rm   ro   rr   ru   rw   rz   r[   r)   r'   r   r   
   sY           #-"*Z"8"8x888E3NNNCD#NNNFDE3NNNE3D#NNNGSGSGSFCD#K	# K K K XK
 %* % % % X% _E3 E4 E E E _E &D & & & X& # # # # # # DD D D D XD
 8 8 8 8 X8 3    X .c .d . . . . _`CG
 
z 
* 
Z 
Q[ 
sm
19%
LP
 
 
 
* * * *]c3h ] ] ] ]EJ E4 E E E ECF Ct C C C CBF Bt B B B B
AF At A A A A
BF Bt B B B B
AF At A A A A
BF Bt B B B B
y# y y y y y yr)   r   )r   r*   typingr   r   r   r   r   r.   commonr	   timer
   r   	dataclassr   r[   r)   r'   <module>r      s    				  ; ; ; ; ; ; ; ; ; ; ; ; ; ;           & & & & & & & & Ee5999ey ey ey ey ey ey ey :9ey ey eyr)   