
    }Kg"                       d Z ddlmZ ddlmZmZmZmZmZ 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 ddlZddlmZ d	d
lmZ g dZe	j.                  j1                  d ej2                  d            Z ej6                  edd      Z ej:                  dd      5 Zej?                   e e             dejB                  d<   ddd        ej:                  dd      5 Z"e"jG                  d      5 Z$ ejJ                  e$      Z&ddd       ddd       ddddZ'e'Z(	 d dZ)d!dZ*dddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ+d#dZ,d$d%dZ-y# 1 sw Y   xY w# 1 sw Y   QxY w# 1 sw Y   UxY w)&z(Utility functions for dealing with files    )annotations)ListOptionalUnionAnySetN)	resources)Path   )ParameterError   )version)
find_filesexampleexlist_examplesexample_infoLIBROSA_DATA_DIRlibrosazhttps://librosa.org/data/audio/)base_urlregistryzlibrosa.util.example_datazregistry.txtversion_index.msgpackz
index.jsonrF)hqc                   | t         vrt        d|        |rd}nd}t        t        j	                  t         |    d   |z               S )aQ  Retrieve the example recording identified by 'key'.

    The first time an example is requested, it will be downloaded from
    the remote repository over HTTPS.
    All subsequent requests will use a locally cached copy of the recording.

    For a list of examples (and their keys), see `librosa.util.list_examples`.

    By default, local files will be cached in the directory given by
    `pooch.os_cache('librosa')`.  You can override this by setting
    an environment variable ``LIBROSA_DATA_DIR`` prior to importing librosa:

    >>> import os
    >>> os.environ['LIBROSA_DATA_DIR'] = '/path/to/store/data'
    >>> import librosa

    Parameters
    ----------
    key : str
        The identifier for the track to load
    hq : bool
        If ``True``, return the high-quality version of the recording.
        If ``False``, return the 22KHz mono version of the recording.

    Returns
    -------
    path : str
        The path to the requested example file

    Examples
    --------
    Load "Hungarian Dance #5" by Johannes Brahms

    >>> y, sr = librosa.load(librosa.example('brahms'))

    Load "Vibe Ace" by Kevin MacLeod (the example previously packaged with librosa)
    in high-quality mode

    >>> y, sr = librosa.load(librosa.example('vibeace', hq=True))

    See Also
    --------
    librosa.util.list_examples
    pooch.os_cache
    Unknown example key: z.hq.oggz.oggpath)
__TRACKMAPr   str	__GOODBOYfetch)keyr   exts      V/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/librosa/util/files.pyr   r   -   sO    \ *4SE:;;	yz#v6<=>>    c                     t        d       t        d       t        t        j                               D ]#  } | dk(  r	t        | ddt        |    d           % y)a=  List the available audio recordings included with librosa.

    Each recording is given a unique identifier (e.g., "brahms" or "nutcracker"),
    listed in the first column of the output.

    A brief description is provided in the second column.

    See Also
    --------
    util.example
    util.example_info
    zAVAILABLE EXAMPLESD--------------------------------------------------------------------pibble10	descN)printsortedr   keys)r"   s    r$   r   r   j   sS     

	(Ojoo'((?R:c?62345	 )r%   c                *   | t         vrt        d|        t        j                  t         |    d   dz         }t	        |d      5 }t        | ddt         |    d   d       t        d	       |D ]  }t        |        	 d
d
d
       y
# 1 sw Y   y
xY w)a  Display licensing and metadata information for the given example recording.

    The first time an example is requested, it will be downloaded from
    the remote repository over HTTPS.
    All subsequent requests will use a locally cached copy of the recording.

    For a list of examples (and their keys), see `librosa.util.list_examples`.

    By default, local files will be cached in the directory given by
    `pooch.os_cache('librosa')`.  You can override this by setting
    an environment variable ``LIBROSA_DATA_DIR`` prior to importing librosa.

    Parameters
    ----------
    key : str
        The identifier for the recording (see `list_examples`)

    See Also
    --------
    librosa.util.example
    librosa.util.list_examples
    pooch.os_cache
    r   r   z.txtr   10sr*   r+   sr'   N)r   r   r    r!   openr,   )r"   license_filefdesclines       r$   r   r      s    0 *4SE:;;??:c?6#:V#CDL	lC	 ES	JsOF3A678hD$K  
!	 	 s   :B		BT)r#   recursecase_sensitivelimitoffsetc                  |g d}nt        |t              r|g}t        |      }|s>|D ch c]  }|j                          }}||D ch c]  }|j	                          c}z  }t               }|r-t        j                  |       D ]  }|t        |d   |      z  } nt        | |      }t        |      }	|	j                          |	|d }	||	d| }	|	S c c}w c c}w )a@  Get a sorted list of (audio) files in a directory or directory sub-tree.

    Examples
    --------
    >>> # Get all audio files in a directory sub-tree
    >>> files = librosa.util.find_files('~/Music')

    >>> # Look only within a specific directory, not the sub-tree
    >>> files = librosa.util.find_files('~/Music', recurse=False)

    >>> # Only look for mp3 files
    >>> files = librosa.util.find_files('~/Music', ext='mp3')

    >>> # Or just mp3 and ogg
    >>> files = librosa.util.find_files('~/Music', ext=['mp3', 'ogg'])

    >>> # Only get the first 10 files
    >>> files = librosa.util.find_files('~/Music', limit=10)

    >>> # Or last 10 files
    >>> files = librosa.util.find_files('~/Music', offset=-10)

    >>> # Avoid including search patterns in the path string
    >>> import glob
    >>> directory = '~/[202206] Music'
    >>> directory = glob.escape(directory)  # Escape the special characters
    >>> files = librosa.util.find_files(directory)

    Parameters
    ----------
    directory : str
        Path to look for files

    ext : str or list of str
        A file extension or list of file extensions to include in the search.

        Default: ``['aac', 'au', 'flac', 'm4a', 'mp3', 'ogg', 'wav']``

    recurse : boolean
        If ``True``, then all subfolders of ``directory`` will be searched.

        Otherwise, only ``directory`` will be searched.

    case_sensitive : boolean
        If ``False``, files matching upper-case version of
        extensions will be included.

    limit : int > 0 or None
        Return at most ``limit`` files. If ``None``, all files are returned.

    offset : int
        Return files starting at ``offset`` within the list.

        Use negative values to offset from the end of the list.

    Returns
    -------
    files : list of str
        The list of audio files.
    N)aacauflacm4amp3oggwavr   )

isinstancer   setlowerupperoswalk__get_fileslistsort)
	directoryr#   r6   r7   r8   r9   efilesetrG   filess
             r$   r   r      s    J {?	C	e c(C "%&#Qqwwy#&3'3a	3''eGGGI&D{47C00G ' i-ME	JJL&'NEfuL% ''s   C
Cc                ^   t         j                  j                  t         j                  j                  |             } t	               }|D ]a  }t         j                  j                  | dt         j                  j                  z   |z         }|t	        t        j                  |            z  }c |S )z)Get a list of files in a single directory*)rF   r   abspath
expanduserrC   joinextsepglob)dir_name
extensionsmyfilessub_extglobstrs        r$   rH   rH   
  s{     wwrww11(;<HeG'',,xrww~~)=)GH3tyy)**  Nr%   c                   | t         } t        j                  d      }t        |d      5 }t	        j
                  |      }ddd       | vr"d| v rt        d|  d      t        d|  d      d||     S # 1 sw Y   7xY w)	a  Print the citation information for librosa.

    Parameters
    ----------
    version : str or None
        The version of librosa to cite. If None, the current version is used.

    Returns
    -------
    doi : str
        The DOI for the given version of librosa.

    Raises
    ------
    ParameterError
        If the requested version is not found in the citation index.

    Examples
    --------
    >>> librosa.cite("0.10.1")
    "https://doi.org/10.5281/zenodo.8252662"
    Nr   rbdevzVersion zC is not yet released and therefore does not yet have a citable DOI.z  not found in the citation indexzhttps://doi.org/)librosa_versionr    r!   r2   msgpackloadr   )r   version_datar4   version_indexs       r$   citerc     s    . !??#:;L	lD	!UU+ 
" m#G 8G94w!xyy 8G94T!UVVmG4566 
"	!s   A66A?)r"   r   r   boolreturnr   )re   None)r"   r   re   rf   )rK   Union[str, os.PathLike[Any]]r#   zOptional[Union[str, List[str]]]r6   rd   r7   rd   r8   zOptional[int]r9   intre   z	List[str])rV   rg   rW   zSet[str])N)r   zOptional[str]re   r   ).__doc__
__future__r   typingr   r   r   r   r   rF   rU   jsonr_   	importlibr	   pathlibr
   pooch
exceptionsr   r   r^   __all__environgetos_cache__data_pathcreater    r   regload_registryr   r   indexr2   _fdescr`   r   r   r   r   r   r   rH   rc    r%   r$   <module>r|      s   / " 2 2 	       & 0 jjnn/	1JKELL;d	 Y^^/@CCH%26I./ A
 Y^^/>%	CFTYYv&
 
 ?
 %* 6?r  6,!N ,0 c+c 
)c 	c
 c c c cL$7k A@ 
 ?>s0   'EE/EEEE	EE'