o
    2j'                     @   s   d dl Z d dlmZmZ d dlmZ e je jG dd dZe 	e
e
 Ze je jG dd dZe jded	e jd
efddZe jG dd dZe je jG dd deZe je jG dd dZe je jG dd deZdS )    N)PyBuffer_FillInfoPyBytes_FromString)memcpyc                   @   s   e Zd Zdd ZdS )SubtitleProxyc                 C   s   t t| j d S N)libavsubtitle_freecythonaddressstructself r   P/var/www/html/whisper/venv/lib/python3.10/site-packages/av/subtitles/subtitle.py__dealloc__	   s   zSubtitleProxy.__dealloc__N)__name__
__module____qualname__r   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZd$ddZe		d%deded	ed
ededefddZ	dd Z
edd ZejdefddZedd ZejdefddZedd ZejdefddZedd ZejdefddZdd Zd d! Zd"d# ZdS )&SubtitleSetzm
    A :class:`SubtitleSet` can contain many :class:`Subtitle` objects.

    Wraps :ffmpeg:`AVSubtitle`.
    Nc                    sX   |t u rt  _d _d S t|tr(| _t fddt jjjD  _d S t	d)Nr   c                 3   s    | ]}t  |V  qd S r   )build_subtitle.0ir   r   r   	<genexpr>!   s    

z(SubtitleSet.__cinit__.<locals>.<genexpr>z@SubtitleSet requires a SubtitleProxy or use SubtitleSet.create())
_cinit_bypass_sentinelr   proxyrects
isinstancetupleranger   	num_rects	TypeError)r   proxy_or_sentinelr   r   r   	__cinit__   s   

zSubtitleSet.__cinit__r      textstartendptssubtitle_formatreturnc              	   C   s  t t}||jj_||jj_||jj_||jj_d|jj_t	
t	jt	jtj  tt	t	jtj |jj_|jjjt	jkrCtdt	
t	jtj tt	tj}|t	jkrkt|jjj t	j|jj_td||jjjd< d|_d|_d|_d|_d|_tj|_t	j|_d|_t| }t	
t	jt|d |_ |j t	jkrtdt!|j t	
t	j| | d|j |< t"|df|_|S )a  
        Create a SubtitleSet for encoding.

        :param text: The subtitle text in ASS dialogue format
            (e.g. ``b"0,0,Default,,0,0,0,,Hello World"``)
        :param start: Start display time as offset from pts (typically 0)
        :param end: End display time as offset from pts (i.e., duration)
        :param pts: Presentation timestamp in stream time_base units
        :param subtitle_format: Subtitle format (default 1 for text)
        :return: A SubtitleSet ready for encoding

        .. note::
            All timing values should be in stream time_base units.
            For MKV (time_base=1/1000), units are milliseconds.
            For MP4 (time_base=1/1000000), units are microseconds.
        r$   z'Failed to allocate subtitle rects arrayz Failed to allocate subtitle rectr   z Failed to allocate subtitle text)#r   r   r   r   formatstart_display_timeend_display_timer(   r    r	   castpointerr   AVSubtitleRect
av_malloczsizeofr   NULLMemoryErrorav_freexywh	nb_colorsSUBTITLE_ASStyper%   flagslenp_char	av_mallocassr   AssSubtitle)r%   r&   r'   r(   r)   subsetrecttext_lenr   r   r   create)   sJ   








zSubtitleSet.createc                 C   s&   d| j j d| j j dt| ddS )N<. at 0xr6   >)	__class__r   r   idr   r   r   r   __repr__o   s   $zSubtitleSet.__repr__c                 C   
   | j jjS r   r   r   r+   r   r   r   r   r+   t      
zSubtitleSet.formatvaluec                 C      || j j_d S r   rO   r   rQ   r   r   r   r+   x      c                 C   rN   r   r   r   r,   r   r   r   r   r,   |   rP   zSubtitleSet.start_display_timec                 C   rR   r   rU   rS   r   r   r   r,      rT   c                 C   rN   r   r   r   r-   r   r   r   r   r-      rP   zSubtitleSet.end_display_timec                 C   rR   r   rV   rS   r   r   r   r-      rT   c                 C   rN   )z$Same as packet pts, in av.time_base.r   r   r(   r   r   r   r   r(      s   
zSubtitleSet.ptsc                 C   rR   r   rW   rS   r   r   r   r(      rT   c                 C   
   t | jS r   )r>   r   r   r   r   r   __len__      
zSubtitleSet.__len__c                 C   rX   r   )iterr   r   r   r   r   __iter__   rZ   zSubtitleSet.__iter__c                 C   
   | j | S r   )r   r   r   r   r   r   __getitem__   rZ   zSubtitleSet.__getitem__r   )r   r$   )r   r   r   __doc__r#   staticmethodbytesintr   rF   rM   propertyr+   setterr,   r-   r(   rY   r\   r_   r   r   r   r   r      sN    
E



r   subtitleindexr*   c                 C   s|   |dk st t j|| jjjkrtd| jjj| }|jt	j
kr&t| |S |jt	jks2|jt	jkr7t| |S td|j )zBuild an av.Stream for an existing AVStream.

    The AVStream MUST be fully constructed and ready for use before this is called.
    r    subtitle rect index out of rangezunknown subtitle type %r)r	   r.   uintr   r   r    
ValueErrorr   r<   r   SUBTITLE_BITMAPBitmapSubtitler;   SUBTITLE_TEXTrB   )rf   rg   ptrr   r   r   r      s    

r   c                   @   s,   e Zd ZdZdedejfddZdd ZdS )	Subtitlezg
    An abstract base class for each concrete type of subtitle.
    Wraps :ffmpeg:`AVSubtitleRect`
    rf   rg   c                 C   s   |dk st t j||jjjkrtd|j| _| jjj| | _| jj	t
jkr,d| _	d S | jj	t
jkr8d| _	d S | jj	t
jkrDd| _	d S | jj	t
jkrPd| _	d S td| jj	)Nr   rh   s   nones   bitmaps   texts   asszunknown subtitle type )r	   r.   ri   r   r   r    rj   r   rn   r<   r   SUBTITLE_NONErk   rm   r;   r   rf   rg   r   r   r   r#      s   



zSubtitle.__cinit__c                 C   s   d| j j dt| ddS )Nz<av.rI   r6   rJ   )rK   r   rL   r   r   r   r   rM      s   zSubtitle.__repr__N)	r   r   r   r`   r   r	   rc   r#   rM   r   r   r   r   ro      s    ro   c                   @   s|   e Zd ZdedejfddZdd Zedd Z	ed	d
 Z
edd Zedd Zedd Zdd Zdd Zdd ZdS )rl   rf   rg   c                    s    t  fddtdD  _d S )Nc                 3   s&    | ]} j j| rt |V  qd S r   )rn   linesizeBitmapSubtitlePlaner   r   r   r   r      s    
z+BitmapSubtitle.__cinit__.<locals>.<genexpr>   )r   r   planesrq   r   r   r   r#      s   zBitmapSubtitle.__cinit__c                 C   sF   d| j j d| j j d| j d| j d| j d| j dt| ddS )	NrG   rH    r6   z at ,z; at 0xrJ   )rK   r   r   widthheightr6   r7   rL   r   r   r   r   rM      s   zBitmapSubtitle.__repr__c                 C      | j jS r   )rn   r6   r   r   r   r   r6         zBitmapSubtitle.xc                 C   rz   r   )rn   r7   r   r   r   r   r7      r{   zBitmapSubtitle.yc                 C   rz   r   )rn   r8   r   r   r   r   rx      r{   zBitmapSubtitle.widthc                 C   rz   r   )rn   r9   r   r   r   r   ry      r{   zBitmapSubtitle.heightc                 C   rz   r   )rn   r:   r   r   r   r   r:      r{   zBitmapSubtitle.nb_colorsc                 C   rX   r   )r>   ru   r   r   r   r   rY      rZ   zBitmapSubtitle.__len__c                 C   rX   r   )r[   ru   r   r   r   r   r\      rZ   zBitmapSubtitle.__iter__c                 C   r]   r   )ru   r^   r   r   r   r_      rZ   zBitmapSubtitle.__getitem__N)r   r   r   r   r	   rc   r#   rM   rd   r6   r7   rx   ry   r:   rY   r\   r_   r   r   r   r   rl      s     




rl   c                   @   s:   e Zd ZdedejfddZdeje dejfddZ	d	S )
rs   rf   rg   c                 C   s^   |dkrt d|jj| st d|| _|| _|jj|jj | _t	tj
|jj| | _d S )Nrt   z"BitmapSubtitles have only 4 planeszplane does not exist)rj   rn   rr   rf   rg   r8   r9   buffer_sizer	   r.   p_voiddata_bufferrq   r   r   r   r#      s   zBitmapSubtitlePlane.__cinit__viewr=   c                 C   s   t || | j| jd| d S )Nr   )r   r   r|   )r   r   r=   r   r   r   __getbuffer__     z!BitmapSubtitlePlane.__getbuffer__N)
r   r   r   rl   r	   rc   r#   r/   	Py_bufferr   r   r   r   r   rs      s    rs   c                   @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Zd
S )rB   zY
    Represents an ASS/Text subtitle format, as opposed to a bitmap Subtitle format.
    c                 C   s   d| j dt| ddS )Nz<av.AssSubtitle rI   r6   rJ   )dialoguerL   r   r   r   r   rM     r   zAssSubtitle.__repr__c                 C      | j jtjurt| j jS dS )zl
        Returns the subtitle in the ASS/SSA format. Used by the vast majority of subtitle formats.
            )rn   rA   r	   r3   r   r   r   r   r   rA        zAssSubtitle.assc           	      C   s  d}d}d}| j }ttj\}}t }t|}|dk r6||k r6|| dkr*|d7 }|d7 }|dk r6||k s ||k r|| }|d |krFdn||d  }|dkr^|dkr^|d |d	7 }q6|sq|d
krk|dkrkd}n|| n|dkrwd}|d7 }||k s:t|S )zK
        Extract the dialogue from the ass format. Strip comments.
        r   F   ,   r$   \   N   
      {   T}   )rA   r	   declareuchar	bytearrayr>   appendrb   )	r   comma_countr   stateass_textchar	next_charresultrE   r   r   r   r   #  s8   
zAssSubtitle.dialoguec                 C   r   )zN
        Rarely used attribute. You're probably looking for dialogue.
        r   )rn   r%   r	   r3   r   r   r   r   r   r%   I  r   zAssSubtitle.textN)	r   r   r   r`   rM   rd   rA   r   r%   r   r   r   r   rB     s    

%rB   )r	   cython.cimports.cpythonr   r   cython.cimports.libc.stringr   finalcclassr   r   objectr   r   cfuncrc   ro   r   rl   rs   rB   r   r   r   r   <module>   s0     *