o
    ]i                     @   s   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 ee	Z
ddedee fddZd	ed
edefddZd
edefddZd
edefddZdS )    N)Iterator)urlopenFcheck_writablereturnc                 c   s    zt jd V  W n	 ty   Y nw t jdkr$t jtjddV  d S g d}ttdr4|	dtj |D ]&}t j|dd}| rYt j
|rQt |t jsPq6nt |t jsYq6|V  q6t jt jdd	dV  d S )
NPYAV_TESTDATA_DIRntpyavdatasets)z/usr/local/sharez/usr/local/libz
/usr/sharez/usr/libreal_prefixr   ~z.pyav)osenvironKeyErrornamepathjoinsysprefixhasattrinsertexistsaccessW_OK
expanduser)r   basesbasedir_ r   ?/home/ubuntu/.local/lib/python3.10/site-packages/av/datasets.pyiter_data_dirs   s.   

r   urlr   c           
   
   C   sV  t j|}||krt| dt D ]}t j||}t j|r'|  S qttd}t j||}t	d|  d|  t
| }| dkrStd|  t j|}zt | W n tyy } z|jtjkro W Y d}~nd}~ww |d }t|d	}	 |d
}	|	r||	 nnqW d   n1 sw   Y  t || |S )ag  Download the data at a URL, and cache it under the given name.

    The file is stored under `pyav/test` with the given name in the directory
    :envvar:`PYAV_TESTDATA_DIR`, or the first that is writeable of:

    - the current virtualenv
    - ``/usr/local/share``
    - ``/usr/local/lib``
    - ``/usr/share``
    - ``/usr/lib``
    - the user's home

    z is not normalized.TzDownloading z to    zHTTP Nz.tmpwbi   )r   r   normpath
ValueErrorr   r   r   nextloginfor   getcodedirnamemakedirsOSErrorerrnoEEXISTopenreadwriterename)
r    r   
clean_namer   r   responseetmp_pathfhchunkr   r   r   cached_download.   sF   

r8   c              	   C   $   t d|  tjd| dtjjS )zDownload and return a path to a sample from the FFmpeg test suite.

    Data is handled by :func:`cached_download`.

    See the `FFmpeg Automated Test Environment <https://www.ffmpeg.org/fate.html>`_

    z"http://fate.ffmpeg.org/fate-suite/z
fate-suite/r8   r   r   r   replacesepr   r   r   r   fated   s   r?   c              	   C   r9   )zDownload and return a path to a sample that is curated by the PyAV developers.

    Data is handled by :func:`cached_download`.

    zhttps://pyav.org/datasets/zpyav-curatedr:   r;   r>   r   r   r   curatedr   s   r@   )F)r,   loggingr   r   typingr   urllib.requestr   	getLogger__name__r&   boolstrr   r8   r?   r@   r   r   r   r   <module>   s    
#6