U
    ,:%eB                     @   s   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Zd dl	m
Z
 eeZdd Zdd	 ZdddZdddeeeeef eedddZdS )    N)PathLike)Path)Uniondownload_url_to_filec                 C   s.   t tj d t |  }|jjddd |S )NZ
torchaudioT)parentsexist_ok)r   torchZhubZget_dirparentmkdir)keypath r   X/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/torchaudio/utils/download.py_get_local_path   s    r   c                 C   s   d|  }t |||d d S )Nz(https://download.pytorch.org/torchaudio/progressr   )r   r   r   urlr   r   r   	_download   s    
r     c              	   C   sJ   t  }t| d*}||}|r8|| ||}qW 5 Q R X | S )Nrb)hashlibsha256openreadupdate	hexdigest)r   hash
chunk_sizemfiledatar   r   r   	_get_hash   s    

r"    Tr   )r   r   r   r   returnc                C   s   |p
t | }| r"td| ntd| | t| ||d |rtd t||}||krztd| d| d| dtd	 t|S )
a4  Download and store torchaudio assets to local file system.

    If a file exists at the download path, then that path is returned with or without
    hash validation.

    Args:
        key (str): The asset identifier.
        hash (str, optional):
            The value of SHA256 hash of the asset. If provided, it is used to verify
            the downloaded / cached object. If not provided, then no hash validation
            is performed. This means if a file exists at the download path, then the path
            is returned as-is without verifying the identity of the file.
        path (path-like object, optional):
            By default, the downloaded asset is saved in a directory under
            :py:func:`torch.hub.get_dir` and intermediate directories based on the given `key`
            are created.
            This argument can be used to overwrite the target location.
            When this argument is provided, all the intermediate directories have to be
            created beforehand.
        progress (bool): Whether to show progress bar for downloading. Default: ``True``.

    Note:
        Currently the valid key values are the route on ``download.pytorch.org/torchaudio``,
        but this is an implementation detail.

    Returns:
        str: The path to the asset on the local file system.
    z2The local file (%s) exists. Skipping the download.zDownloading %s to %sr   zVerifying the hash value.z'The hash value of the downloaded file (z), 'z+' does not match the provided hash value, 'z'.zHash validated.)r   exists_LGinfor   r"   
ValueErrorstr)r   r   r   r   digestr   r   r   download_asset"   s    #


r+   )r   )r#   r#   )r   loggingosr   pathlibr   typingr   r	   Ztorchaudio._internalr   	getLogger__name__r&   r   r   r"   r)   boolr+   r   r   r   r   <module>   s*   

  
