
    Hui                         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j                  e	      Z
ddedee   fdZdededefd	Zdedefd
ZdedefdZy)    N)Iterator)urlopencheck_writablereturnc              #     K   	 t         j                  d    t         j                  dk(  r2t         j                  j                  t        j                  dd       y g d}t        t        d      r |j                  dt        j                         |D ]  }t         j                  j                  |dd      }| rit         j                  j                  |      r%t        j                  |t         j                        s&jt        j                  |t         j                        s|  t         j                  j                  t         j                  j                  d      d	d       y # t        $ r Y ]w xY ww)
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_s       =/opt/pipecat/venv/lib/python3.12/site-packages/av/datasets.pyiter_data_dirsr       s    jj,-- 
ww$ggll3::vz::E sM"Q

# 	ww||D&*5ww~~d#yyrww/yyrww/
	 '',,rww))#.
DD;  s(   E:E* EE:*	E73E:6E77E:urlr   c                    t         j                  j                  |      }||k7  rt        | d      t	               D ]E  }t         j                  j                  ||      }t         j                  j                  |      sC|c S  t        t	        d            }t         j                  j                  ||      }t        j                  d|  d|        t        |       }|j                         dk7  rt        d|j                                t         j                  j                  |      }	 t        j                  |       |dz   }t#        |d	      5 }	 |j%                  d
      }	|	r|j'                  |	       nn'	 ddd       t        j(                  ||       |S # t        $ r(}|j                  t        j                   k7  r Y d}~d}~ww xY w# 1 sw Y   UxY w)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chunks
             r   cached_downloadr:   .   s    !!$'JTD6!4566  ww||D$'77>>$K
 t$%D77<<d#DHH|C5TF+,s|HS 5!1!1!3 456677??4 D
D
 f}H	h	 MM$'E 
  IIhK  77ell" #
 s$   .F )G	G'G

GGc           
          t        d| z   t        j                  j                  d| j	                  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/r:   r   r   r   replacesepr   s    r   faterA   d   s>     ,t3
\4<<RWW[[#AB     c           
          t        d| z   t        j                  j                  d| j	                  dt        j                  j
                                    S )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@   s    r   curatedrD   r   s>     $t+
^T\\#rww{{%CD rB   )F)r.   loggingr   r   typingr   urllib.requestr   	getLogger__name__r(   boolstrr    r:   rA   rD    rB   r   <module>rM      s      	 
  "g! E4  EHSM  EF3 3C 3C 3ls s 	# 	# 	rB   