Ë
    ¼Ó^jæ  ã                  ó�   — d dl m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
 d dlmZ d dlmZmZ d d	lmZ  ee«      Zdd
„Zdd„Zy)é    )ÚannotationsN)Úmd5)ÚPath)Úcopyfileobj)Úget)Útqdm)ÚMEDIA_ASSETSÚAssets)Ú_get_loggerc                óä   — t         j                  j                  | «      syt        | d«      5 }|j	                  «       }t        |d¬«      }ddd«       j                  «       |k(  S # 1 sw Y   ŒxY w)aˆ  
    Check if the MD5 hash of a file matches the original hash.

    Note: MD5 is used here for file integrity checking (detecting corruption),
    not for cryptographic security purposes.

    Args:
        filename: The path to the file to be checked.
        original_md5_hash: The original MD5 hash to compare against.

    Returns:
        True if the hashes match, False otherwise.
    FÚrb)ÚusedforsecurityN)ÚosÚpathÚexistsÚopenÚreadr   Ú	hexdigest)ÚfilenameÚoriginal_md5_hashÚfileÚfile_contentsÚcomputed_md5_hashs        úh/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/supervision/assets/downloader.pyÚis_md5_hash_matchingr      sk   € ô �7‰7�>‰>˜(Ô#Øä	ˆh˜Ó	ð F ØŸ	™	›ˆÜ ¸uÔEÐ÷Fð ×&Ñ&Ó(Ð,=Ñ=Ð=÷	Fð Fús   ­A&Á&A/c                óæ  — t        | t        «      r| j                  n| }|t        v �ryt	        |«      j                  «       sýt        j                  d|«       t        t        |   d   ddd¬«      }|j                  «        t        |j                  j                  dd«      «      }t	        |«      j                  «       j                  «       }|j                  j                  dd¬«       t!        j"                  |j$                  d|d	d
¬«      5 }|j'                  d«      5 }t)        ||«       ddd«       ddd«       |S t+        |t        |   d   «      s5t        j-                  d«       t/        j0                  |«       t3        |«      S t        j                  d|«       |S dj5                  d„ t        j6                  «       D «       «      }t9        d|› d�«      ‚# 1 sw Y   Œ¯xY w# 1 sw Y   |S xY w)a   
    Download a specified asset if it doesn't already exist or is corrupted.

    Args:
        asset_name: The name or type of the asset to be downloaded.

    Returns:
        The filename of the downloaded asset.

    Example:
        ```pycon
        >>> from supervision.assets import download_assets, ImageAssets, VideoAssets
        >>> download_assets(VideoAssets.VEHICLES)  # doctest: +SKIP
        'vehicles.mp4'

        >>> download_assets(ImageAssets.PEOPLE_WALKING)  # doctest: +SKIP
        'people-walking.jpg'

        ```
    zDownloading %s assetsr   Té   )ÚstreamÚallow_redirectsÚtimeoutzContent-Length)ÚparentsÚexist_okr   Ú z#a351fb)ÚtotalÚdescÚcolourÚwbNé   z!File corrupted. Re-downloading...z%s asset download complete.z, c              3  ó    K  — | ]  }|–— Œ y ­w)N© )Ú.0r   s     r   ú	<genexpr>z"download_assets.<locals>.<genexpr>Z   s   è ø€ Ò N¨h¤Ñ Nùs   ‚z2Invalid asset. It should be one of the following: ú.)Ú
isinstancer
   r   r	   r   r   ÚloggerÚinfor   Úraise_for_statusÚintÚheadersÚ
expanduserÚresolveÚparentÚmkdirr   ÚwrapattrÚrawr   r   r   Úwarningr   ÚremoveÚdownload_assetsÚjoinÚkeysÚ
ValueError)Ú
asset_namer   ÚresponseÚ	file_sizeÚfolder_pathÚraw_respr   Úvalid_assetss           r   r<   r<   )   s²  € ô, '1°¼VÔ&Dˆz×"Ò"È*€Hà”<ÒÜ�H‹~×$Ñ$Ô&Ü�K‰KÐ/°Ô:ÜÜ˜XÑ& qÑ)°$ÈÐVXôˆHð ×%Ñ%Ô'ä˜H×,Ñ,×0Ñ0Ð1AÀ1ÓEÓFˆIÜ˜x›.×3Ñ3Ó5×=Ñ=Ó?ˆKØ×Ñ×$Ñ$¨T¸DÐ$ÔAä—‘Ø—‘˜f¨I¸BÀyôð 0àØ ×%Ñ% dÓ+ð 0¨tÜ ¨$Ô/÷0÷0ð$ €Oô (¨´,¸xÑ2HÈÑ2KÔLÜ—‘ÐBÔCÜ—	‘	˜(Ô#Ü& xÓ0Ð0ä�K‰KÐ5°xÔ@ð €Oð —y‘yÑ N¼,×:KÑ:KÓ:MÔ NÓNˆÜØ@ÀÀÈaÐPó
ð 	
÷0ð 0ú÷0ð$ €Oús$   ÄG&ÄGÄ,G&ÇG#	ÇG&Ç&G0)r   Ústrr   rF   ÚreturnÚbool)r@   zAssets | strrG   rF   )Ú
__future__r   r   Úhashlibr   Úpathlibr   Úshutilr   Úrequestsr   Ú	tqdm.autor   Úsupervision.assets.listr	   r
   Úsupervision.utils.loggerr   Ú__name__r/   r   r<   r*   ó    r   ú<module>rS      s4   ðÝ "ã 	Ý Ý Ý å Ý ç 8Ý 0á	�XÓ	€ó>ô06rR   