o
    ii                     @   s   d dl mZ d dlmZ d dlmZmZmZmZ d dl	Z
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mZmZ eeeeed
ZG dd dZdS )    )cached_property)BytesIO)AnyListOptionalUnionN)Codec)naturalsize)Seconds)get_template)pyav	soundfilewave)avr   sfr   r   c                   @   sb  e Zd Z			dFdedee dedeee  fddZ	e
d	efd
dZed	ee fddZe
d	eeef fddZe
d	ee fddZe
d	ejfddZe
d	efddZe
d	efddZe
d	efddZed	efddZed	efddZed	efddZed	efd d!Zed	efd"d#Zed	efd$d%Zed	ee fd&d'Zed	efd(d)Z ed	efd*d+Z!ed	efd,d-Z"ed	efd.d/Z#ed	efd0d1Z$ed	efd2d3Z%e&d4eeeeef  d	efd5d6Z'e&d7eedf d	efd8d9Z(e&d:eedf d	efd;d<Z)e&d=ed>ed	efd?d@Z*e&dAed	efdBdCZ+dDdE Z,dS )GInfoNFfile
frame_sizeforced_decodingbackendsc           	      C   s   || _ |d u rddg}t|D ]S\}}t|tr| nd}zt|t}||||| _| j	d u r9t| jts9W qW  d S  t
yb } zt|trN|| |t|d krX|W Y d }~qd }~ww d S )Nr   r   r      )r   	enumerate
isinstancer   tell	_backendsgetr   backendduration	Exceptionseeklen)	selfr   r   r   r   idxr   pose r%   H/home/ubuntu/.local/lib/python3.10/site-packages/audiolab/reader/info.py__init__%   s(   

zInfo.__init__returnc                 C      | j jS N)r   bits_per_sampler!   r%   r%   r&   r+   >      zInfo.bits_per_samplec                 C   r)   r*   )r   bit_rater,   r%   r%   r&   r.   B   r-   zInfo.bit_ratec                 C   r)   r*   )r   codecr,   r%   r%   r&   r/   F   r-   z
Info.codecc                 C   r)   r*   )r   r   r,   r%   r%   r&   r   J   r-   zInfo.durationc                 C   r)   r*   )r   dtyper,   r%   r%   r&   r0   N   r-   z
Info.dtypec                 C   r)   r*   )r   formatr,   r%   r%   r&   r1   R   r-   zInfo.formatc                 C   r)   r*   )r   layoutr,   r%   r%   r&   r2   V   r-   zInfo.layoutc                 C   r)   r*   )r   namer,   r%   r%   r&   r3   Z   r-   z	Info.namec                 C   r)   r*   )r   num_channelsr,   r%   r%   r&   r4   ^   r-   zInfo.num_channelsc                 C   r)   r*   r   
num_framesr,   r%   r%   r&   r6   b   r-   zInfo.num_framesc                 C   r)   r*   )r   metadatar,   r%   r%   r&   r7   f   r-   zInfo.metadatac                 C   r)   r*   )r   sample_rater,   r%   r%   r&   r8   j   r-   zInfo.sample_ratec                 C   r)   r*   )r   seekabler,   r%   r%   r&   r9   n   r-   zInfo.seekablec                 C   r)   r*   )r   sizer,   r%   r%   r&   r:   r   r-   z	Info.sizec                 C   s   | j d u rd S t| j d dS )NK      )r   roundr,   r%   r%   r&   cdda_sectorsv   s   
zInfo.cdda_sectorsc                 C      | j S r*   )r4   r,   r%   r%   r&   channels|      zInfo.channelsc                 C   r?   r*   )r6   r,   r%   r%   r&   num_samples   s   zInfo.num_samplesc                 C   r?   r*   r8   r,   r%   r%   r&   rate   rA   z	Info.ratec                 C   r?   r*   rC   r,   r%   r%   r&   
samplerate   rA   zInfo.sampleratec                 C   r)   r*   r5   r,   r%   r%   r&   samples   r-   zInfo.samplesc                 C   r?   r*   )r+   r,   r%   r%   r&   	precision   rA   zInfo.precisionsc                 C   s6   | d u rdS t | tst| } ddd |  D S )NN/A c                 s   s     | ]}| d  dV  qdS )0.N)rstrip).0xr%   r%   r&   	<genexpr>   s    z$Info.rstrip_zeros.<locals>.<genexpr>)r   strjoinsplit)rH   r%   r%   r&   rstrip_zeros   s
   
zInfo.rstrip_zerosr.   c                 C   s0   | d u s| dkr
dS t | d} t| d S )Nr   rI   Bbps)r	   rM   r   rT   )r.   r%   r%   r&   format_bit_rate   s   zInfo.format_bit_rater   c                 C   sJ   | d u rdS t | d\}}t |d\}}t|ddt|dd|dS )NrI   i  <   02d:z06.3f)divmodint)r   hoursrestminutessecondsr%   r%   r&   format_duration   s
   "zInfo.format_durationr3   r1   c                 C   sH   |   |  rd|  dS | dv r|  d| dS d|  d| dS )N')z<none>z<stdin>z ()z' ()upperendswith)r3   r1   r%   r%   r&   format_name   s
   zInfo.format_namer:   c                 C   s   | dvrt | } t| S )N)iiN)r	   r   rT   )r:   r%   r%   r&   format_size   s   
zInfo.format_sizec                 C   sj   t djt| j| j| j| j| jt	| j
| jd u rdn| jt| jt| jt| j| j| jdS )NinforI   )r3   r@   rD   rG   r   rF   r>   r:   r.   r/   r7   )r   renderr   rf   r3   r1   r@   rD   rG   ra   r   rF   rT   r>   rh   r:   rW   r.   r/   r7   r,   r%   r%   r&   __str__   s   



zInfo.__str__)NFN)-__name__
__module____qualname__r   r   r\   boolr   rQ   r'   r   r+   propertyr.   r   r   r/   r
   r   npr0   r1   r2   r3   r4   r6   r7   r8   r9   r:   floatr>   r@   rB   rD   rE   rF   rG   staticmethodrT   rW   ra   rf   rh   rk   r%   r%   r%   r&   r   $   s    

"r   )	functoolsr   ior   typingr   r   r   r   numpyrq   av.codecr   humanizer	   audiolab.av.typingr
   audiolab.av.utilsr   audiolab.reader.backendr   r   r   r   r   r%   r%   r%   r&   <module>   s    	