o
    SiM                  	   @   s   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mZ d dl	m
Z
mZmZ dZdedfdee
 d	ed
eddfddZ	dde
dededefddZdS )    N)Path)Optional)default_tools_cachedir)Pathlikeresumable_downloadsafe_extractz7https://github.com/burrmill/sph2pipe/archive/2.5.tar.gzFwheredownload_fromforcereturnc                 C   sR   | du r	t dd} t| } t| ||d tjd| d  gddd td dS )	z
    Install the sph2pipe program to handle sphere (.sph) audio files with
    "shorten" codec compression (needed for older LDC data).

    It downloads an archive and then decompresses and compiles the contents.
    NT)force_mkdir)urlforce_downloadzmake -C sph2pipe-2.5)shellcheckzFinished installing sph2pipe.)r   r   download_and_untar_sph2pipe
subprocessrunlogginginfo)r   r	   r
    r   I/home/ubuntu/.local/lib/python3.10/site-packages/lhotse/tools/sph2pipe.pyinstall_sph2pipe   s   
r   
target_dirr   r   c                 C   s   t | } | d }|d  r|s|S | jddd d}| | }t|||d t|}t|| d W d    |S 1 s=w   Y  |S )Nr   MakefileT)parentsexist_okzsph2pipe-2.5.tar.gz)filenamer   )path)r   is_filemkdirr   tarfileopenr   )r   r   r   sph2pipe_dirtar_nametar_pathtarr   r   r   r   "   s   
r   )F)r   r   r"   pathlibr   typingr   lhotse.tools.envr   lhotse.utilsr   r   r   SPH2PIPE_URLstrboolr   r   r   r   r   r   <module>   s<    
