§
    ezniR  ã                   óê  — 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m	Z	 d dl
mZmZ d dlZd dlZd dlmZmZmZmZmZmZmZ dZd„ d	D ¦   «         d
„ d	D ¦   «         z   d„ dD ¦   «         z   d„ dD ¦   «         z   d„ dD ¦   «         z   d„ dD ¦   «         z   d„ dD ¦   «         z   dgz   Zd„ eD ¦   «         Zd+d„Zd,d„Zd-d„Zd.d„Zd/d „Zd!„ Z	 	 	 	 	 	 	 	 d0d$„Z d1d&„Z!d2d(„Z" e	j#        ¦   «         dddd)d"fd*„Z$dS )3é    N)Úrepeat)Ú
ThreadPool)ÚPath)ÚparseÚrequest)ÚLOGGERÚTQDMÚchecksÚ	clean_urlÚemojisÚ	is_onlineÚurl2fileúultralytics/assetsc                 ó(   — g | ]}d D ]
}d|› |› d�‘ŒŒS ))Ú z-clsz-segz-poseÚyolov8ú.pt© )Ú.0ÚkÚsuffixs      ú{/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/ultralytics/utils/downloads.pyú
<listcomp>r      s7   € ÐlÐlÐl°1ÐNkÐlÐlÀFÐ. Ð. 6Ð.Ð.Ð.ÐlÐlÐlÐló    Únsmlxc                 ó(   — g | ]}d D ]
}d|› |› d�‘ŒŒS ))r   Ú6Úyolov5úu.ptr   )r   r   Ú
resolutions      r   r   r      s7   € ÐaÐaÐa¸ÐW`ÐaÐaÈÐ3 Ð3 :Ð3Ð3Ð3ÐaÐaÐaÐar   c                 ó   — g | ]}d |› d�‘Œ	S )Úyolov3r   r   ©r   r   s     r   r   r      s$   € ÐGÐGÐG¨AÐ' Ð'Ð'Ð'ÐGÐGÐGr   )r   z-sppz-tinyc                 ó   — g | ]}d |› d�‘Œ	S )Ú	yolo_nas_r   r   r#   s     r   r   r      s$   € Ð9Ð9Ð9¨aÐ) 1Ð)Ð)Ð)Ð9Ð9Ð9r   Úsmlc                 ó   — g | ]}d |› d�‘Œ	S )Úsam_r   r   r#   s     r   r   r      s    € Ð3Ð3Ð3¨�}˜a�}�}�}Ð3Ð3Ð3r   Úblc                 ó   — g | ]}d |› d�‘Œ	S )zFastSAM-r   r   r#   s     r   r   r      s$   € Ð7Ð7Ð7¨QÐ( !Ð(Ð(Ð(Ð7Ð7Ð7r   Úsxc                 ó   — g | ]}d |› d�‘Œ	S )zrtdetr-r   r   r#   s     r   r   r      s$   € Ð6Ð6Ð6¨AÐ' Ð'Ð'Ð'Ð6Ð6Ð6r   Úlxzmobile_sam.ptc                 ó6   — g | ]}t          |¦  «        j        ‘ŒS r   )r   Ústemr#   s     r   r   r      s    € ÐAÐAÐA¨•t˜A‘w”w”|ÐAÐAÐAr   Tc                 ó�  — t          j        t          ¦  «        5  t          | ¦  «        } t	          j        | ¦  «        }t          |j        |j        g¦  «        sJ ‚|rPt          j
        | ¦  «        5 }|                     ¦   «         dk    cddd¦  «         cddd¦  «         S # 1 swxY w Y   	 ddd¦  «         dS # 1 swxY w Y   dS )a4  
    Validates if the given string is a URL and optionally checks if the URL exists online.

    Args:
        url (str): The string to be validated as a URL.
        check (bool, optional): If True, performs an additional check to see if the URL exists online.
            Defaults to True.

    Returns:
        (bool): Returns True if the string is a valid URL. If 'check' is True, also returns True if the URL exists online.
            Returns False otherwise.

    Example:
        ```python
        valid = is_url("https://www.example.com")
        ```
    éÈ   NTF)Ú
contextlibÚsuppressÚ	ExceptionÚstrr   ÚurlparseÚallÚschemeÚnetlocr   ÚurlopenÚgetcode)ÚurlÚcheckÚresultÚresponses       r   Úis_urlr@      sV  € õ$ 
Ô	�YÑ	'Ô	'ð ð Ý�#‰hŒhˆÝ” Ñ$Ô$ˆÝ�F”M 6¤=Ð1Ñ2Ô2Ð2Ð2Ð2Øð 	1Ý” Ñ%Ô%ð 1¨Ø×'Ò'Ñ)Ô)¨SÒ0ð1ð 1ð 1ð 1ñ 1ô 1ð 1ðð ð ð ñ ô ð ð ð
1ð 1ð 1ð 1øøøð 1ð 1ð 1ð 1àðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ˆ5s6   šAB;Á1B"Â	B;Â"B&	Â&B;Â)B&	Â*B;Â;B?ÃB?©z	.DS_StoreÚ__MACOSXc                 óÔ   — |D ]d}t          t          | ¦  «                             |¦  «        ¦  «        }t          j        d|› d|› �¦  «         |D ]}|                     ¦   «          ŒŒedS )ao  
    Deletes all ".DS_store" files under a specified directory.

    Args:
        path (str, optional): The directory path where the ".DS_store" files should be deleted.
        files_to_delete (tuple): The files to be deleted.

    Example:
        ```python
        from ultralytics.utils.downloads import delete_dsstore

        delete_dsstore('path/to/dir')
        ```

    Note:
        ".DS_store" files are created by the Apple operating system and contain metadata about folders and files. They
        are hidden system files and can cause issues when transferring files between different operating systems.
    z	Deleting z files: N)Úlistr   Úrglobr   ÚinfoÚunlink)ÚpathÚfiles_to_deleteÚfileÚmatchesÚfs        r   Údelete_dsstorerM   ;   s‚   € ð&  ð ð ˆÝ•t˜D‘z”z×'Ò'¨Ñ-Ô-Ñ.Ô.ˆÝŒÐ7 Ð7Ð7¨gÐ7Ð7Ñ8Ô8Ð8Øð 	ð 	ˆAØ�HŠH‰JŒJˆJˆJð	ðð r   c           	      óø  ‡— ddl m}m}m} t	          | ¦  «         t          | ¦  «        } |                      ¦   «         st          d| › d�¦  «        ‚ˆfd„|                      d¦  «        D ¦   «         }|  	                    d¦  «        }|r|n|}	 ||d|	¦  «        5 }
t          |d	| › d
|› d�d| ¬¦  «        D ]+}|
                     ||                     | ¦  «        ¦  «         Œ,	 ddd¦  «         n# 1 swxY w Y   |S )a  
    Zips the contents of a directory, excluding files containing strings in the exclude list. The resulting zip file is
    named after the directory and placed alongside it.

    Args:
        directory (str | Path): The path to the directory to be zipped.
        compress (bool): Whether to compress the files while zipping. Default is True.
        exclude (tuple, optional): A tuple of filename strings to be excluded. Defaults to ('.DS_Store', '__MACOSX').
        progress (bool, optional): Whether to display a progress bar. Defaults to True.

    Returns:
        (Path): The path to the resulting zip file.

    Example:
        ```python
        from ultralytics.utils.downloads import zip_directory

        file = zip_directory('path/to/dir')
        ```
    r   )ÚZIP_DEFLATEDÚ
ZIP_STOREDÚZipFilezDirectory 'z' does not exist.c                 ót   •‡— g | ]3Š‰                      ¦   «         ¯t          ˆfd „‰D ¦   «         ¦  «        ¯1‰‘Œ4S )c              3   ó*   •K  — | ]}|‰j         vV — Œd S ©N©Úname©r   ÚxrL   s     €r   ú	<genexpr>z+zip_directory.<locals>.<listcomp>.<genexpr>r   s,   øè è € ÐJlÐJlÐ_`È1ÐTUÔTZÈ?ÐJlÐJlÐJlÐJlÐJlÐJlr   )Úis_filer7   ©r   rL   Úexcludes    @€r   r   z!zip_directory.<locals>.<listcomp>r   sJ   øø€ ÐmÐmÐm˜!°q·y²y±{´{ÐmÅsÐJlÐJlÐJlÐJlÐdkÐJlÑJlÔJlÑGlÔGlÐm�AÐmÐmÐmr   Ú*ú.zipÚwzZipping ú to ú...rJ   ©ÚdescÚunitÚdisableN)ÚzipfilerO   rP   rQ   rM   r   Úis_dirÚFileNotFoundErrorrE   Úwith_suffixr	   ÚwriteÚrelative_to)Ú	directoryÚcompressr\   ÚprogressrO   rP   rQ   Úfiles_to_zipÚzip_fileÚcompressionrL   rJ   s     `         r   Úzip_directoryrr   U   s„  ø€ ð* :Ð9Ð9Ð9Ð9Ð9Ð9Ð9Ð9Ð9å�9ÑÔÐÝ�Y‘”€IØ×ÒÑÔð LÝÐ J¨iÐ JÐ JÐ JÑKÔKÐKð nÐmÐmÐm˜yŸš¨sÑ3Ô3ÐmÑmÔm€LØ×$Ò$ VÑ,Ô,€HØ"*Ð:�,�,°
€KØ	ˆ�˜3 Ñ	,Ô	,ð 7°Ý˜Ð,S°yÐ,SÐ,SÀhÐ,SÐ,SÐ,SÐZ`ÐnvÐjvÐwÑwÔwð 	7ð 	7ˆDØ�GŠG�D˜$×*Ò*¨9Ñ5Ô5Ñ6Ô6Ð6Ð6ð	7ð7ð 7ð 7ñ 7ô 7ð 7ð 7ð 7ð 7ð 7ð 7øøøð 7ð 7ð 7ð 7ð €Os   ÂAC/Ã/C3Ã6C3Fc           
      ó@  ‡— ddl m}m}m} t	          | ¦  «                             ¦   «         r || ¦  «        s |d| › d�¦  «        ‚|€t	          | ¦  «        j        } || ¦  «        5 }ˆfd„|                     ¦   «         D ¦   «         }	d„ |	D ¦   «         }
t          |
¦  «        dk    s.t          |	¦  «        dk    rB|	d          	                    d	¦  «        s't	          |¦  «        t	          | ¦  «        j
        z  x}}n'|}t	          |¦  «        t          |
¦  «        d         z  }|                     ¦   «         rLt          |                     ¦   «         ¦  «        r+|s)t          j        d
| › d|› d�¦  «         |cddd¦  «         S t!          |	d| › dt	          |¦  «                             ¦   «         › d�d| ¬¦  «        D ]G}dt	          |¦  «        j        v rt          j        d|› d�¦  «         Œ1|                     ||¦  «         ŒH	 ddd¦  «         n# 1 swxY w Y   |S )aÁ  
    Unzips a *.zip file to the specified path, excluding files containing strings in the exclude list.

    If the zipfile does not contain a single top-level directory, the function will create a new
    directory with the same name as the zipfile (without the extension) to extract its contents.
    If a path is not provided, the function will use the parent directory of the zipfile as the default path.

    Args:
        file (str): The path to the zipfile to be extracted.
        path (str, optional): The path to extract the zipfile to. Defaults to None.
        exclude (tuple, optional): A tuple of filename strings to be excluded. Defaults to ('.DS_Store', '__MACOSX').
        exist_ok (bool, optional): Whether to overwrite existing contents if they exist. Defaults to False.
        progress (bool, optional): Whether to display a progress bar. Defaults to True.

    Raises:
        BadZipFile: If the provided file does not exist or is not a valid zipfile.

    Returns:
        (Path): The path to the directory where the zipfile was extracted.

    Example:
        ```python
        from ultralytics.utils.downloads import unzip_file

        dir = unzip_file('path/to/file.zip')
        ```
    r   )Ú
BadZipFilerQ   Ú
is_zipfilezFile 'z&' does not exist or is a bad zip file.Nc                 óL   •‡— g | ]Št          ˆfd „‰D ¦   «         ¦  «        ¯‰‘Œ S )c              3   ó    •K  — | ]}|‰vV — Œ	d S rT   r   rW   s     €r   rY   z(unzip_file.<locals>.<listcomp>.<genexpr>¡   s'   øè è € Ð4QÐ4QÀA°Q¸a°ZÐ4QÐ4QÐ4QÐ4QÐ4QÐ4Qr   )r7   r[   s    @€r   r   zunzip_file.<locals>.<listcomp>¡   s<   øø€ ÐRÐRÐR�qµÐ4QÐ4QÐ4QÐ4QÈÐ4QÑ4QÔ4QÑ1QÔ1QÐR�ÐRÐRÐRr   c                 óB   — h | ]}t          |¦  «        j        d          ’ŒS )r   )r   Úparts)r   rL   s     r   ú	<setcomp>zunzip_file.<locals>.<setcomp>¢   s%   € Ð:Ð:Ð:¨q�$˜q™'œ'œ-¨Ô*Ð:Ð:Ð:r   é   ú/u   WARNING âš ï¸� Skipping z  unzip as destination directory z is not empty.ú
Unzipping r`   ra   rJ   rb   z..z Potentially insecure file path: z, skipping extraction.)rf   rt   rQ   ru   r   ÚexistsÚparentÚnamelistÚlenÚendswithr/   rD   ÚanyÚiterdirr   Úwarningr	   Úresolvery   Úextract)rJ   rH   r\   Úexist_okrn   rt   rQ   ru   ÚzipObjÚfilesÚtop_level_dirsÚextract_pathrL   s     `          r   Ú
unzip_filer�   |   s´  ø€ ð8 8Ð7Ð7Ð7Ð7Ð7Ð7Ð7Ð7Ð7å�‰JŒJ×ÒÑÔð P J J¨tÑ$4Ô$4ð PØˆjÐN $ÐNÐNÐNÑOÔOÐOØ€|Ý�D‰zŒzÔ ˆð 
ˆ�‰Œð ,˜&ØRÐRÐRÐR˜FŸOšOÑ-Ô-ÐRÑRÔRˆØ:Ð:°EÐ:Ñ:Ô:ˆåˆ~ÑÔ Ò"Ð"¥s¨5¡z¤z°A¢~ ~¸eÀA¼h×>OÒ>OÐPSÑ>TÔ>T ~å"& t¡*¤*­t°D©z¬z¬Ñ">Ð>ˆD�<�<ð  ˆLÝ˜‘:”:¥ ^Ñ 4Ô 4°QÔ 7Ñ7ˆDð �;Š;‰=Œ=ð 	�S §¢¡¤Ñ0Ô0ð 	¸ð 	åŒNÐp°dÐpÐpÐ\`ÐpÐpÐpÑqÔqÐqØð!,ð ,ð ,ð ,ñ ,ô ,ð ,ð ,õ$ �eÐ"R¨tÐ"RÐ"R½¸d¹¼×9KÒ9KÑ9MÔ9MÐ"RÐ"RÐ"RÐY_ÐmuÐiuÐvÑvÔvð 	,ð 	,ˆAà•t˜A‘w”w”}Ð$Ð$Ý”Ð[À!Ð[Ð[Ð[Ñ\Ô\Ð\ØØ�NŠN˜1˜lÑ+Ô+Ð+Ð+ð	,ð%,ð ,ð ,ñ ,ô ,ð ,ð ,ð ,ð ,ð ,ð ,øøøð ,ð ,ð ,ð ,ð2 €Ks   Á(DHÆBHÈHÈHú*https://ultralytics.com/assets/coco128.zipç      ø?c                 óØ  ‡	— 	 t          j        | ¦  «        }|j        dk     sJ d| › d|j        › d|j        › �¦   «         ‚n# t          $ r Y dS w xY wdŠ	t          |j                             dd¦  «        ¦  «        ‰	z  }ˆ	fd	„t          j	        d
¦  «        D ¦   «         \  }}}||z  |k     rdS d|d›d||z  d›d||z  |z
  d›d�}|rt          |¦  «        ‚t          j        |¦  «         dS )aõ  
    Check if there is sufficient disk space to download and store a file.

    Args:
        url (str, optional): The URL to the file. Defaults to 'https://ultralytics.com/assets/coco128.zip'.
        sf (float, optional): Safety factor, the multiplier for the required free space. Defaults to 2.0.
        hard (bool, optional): Whether to throw an error or not on insufficient disk space. Defaults to True.

    Returns:
        (bool): True if there is sufficient disk space, False otherwise.
    i�  zURL error for ú: ú Ti   @úContent-Lengthr   c              3   ó"   •K  — | ]	}|‰z  V — Œ
d S rT   r   )r   rX   Úgibs     €r   rY   z#check_disk_space.<locals>.<genexpr>Ñ   s'   øè è € ÐAÐA Q˜˜S™ÐAÐAÐAÐAÐAÐAr   r|   u,   WARNING âš ï¸� Insufficient free disk space z.1fz GB < z.3fz GB required, Please free z( GB additional disk space and try again.F)ÚrequestsÚheadÚstatus_codeÚreasonr4   ÚintÚheadersÚgetÚshutilÚ
disk_usageÚMemoryErrorr   r…   )
r<   ÚsfÚhardÚrÚdataÚtotalÚusedÚfreeÚtextr•   s
            @r   Úcheck_disk_spacer¨   ¼   sX  ø€ ðÝŒM˜#ÑÔˆØŒ}˜sÒ"Ð"Ð"Ð$V°SÐ$VÐ$V¸A¼MÐ$VÐ$VÈAÌHÐ$VÐ$VÑ"Ô"Ð"Ð"øÝð ð ð Øˆtˆtðøøøð €CÝˆqŒy�}Š}Ð-¨qÑ1Ô1Ñ2Ô2°SÑ8€DØAÐAÐAÐA­&Ô*;¸CÑ*@Ô*@ÐAÑAÔAÑ€Eˆ4�Øˆb�y�4ÒÐØˆtðZ¸4Ðhð Zð ZÈ4ÐRTÉ9Ðhð Zð ZØ "™9 tÑ+ÐYðZð Zð Z€Dàð  Ý˜$ÑÔÐÝ
„N�4ÑÔÐØˆ5s   ƒ<A  Á 
AÁAc                 óz  — |                       d¦  «        d                               d¦  «        d         }d|› �}d}t          j        ¦   «         5 }|                     |d¬¦  «        }d	t	          |j                             ¦   «         ¦  «        v r t          t          d
| › d�¦  «        ¦  «        ‚|j	         
                    ¦   «         D ]"\  }}|                     d¦  «        r|d|› �z  }Œ#|j                             d¦  «        }|rt          j        d|¦  «        d         }ddd¦  «         n# 1 swxY w Y   ||fS )ax  
    Retrieves the direct download link and filename for a shareable Google Drive file link.

    Args:
        link (str): The shareable link of the Google Drive file.

    Returns:
        (str): Direct download URL for the Google Drive file.
        (str): Original filename of the Google Drive file. If filename extraction fails, returns None.

    Example:
        ```python
        from ultralytics.utils.downloads import get_google_drive_file_info

        link = "https://drive.google.com/file/d/1cqT-cJgANNrhIHCrEufUYhQ4RqiWG_lJ/view?usp=drive_link"
        url, filename = get_google_drive_file_info(link)
        ```
    z/d/r{   z/viewr   z/https://drive.google.com/uc?export=download&id=NT)Ústreamzquota exceededui   â�Œ  Google Drive file download quota exceeded. Please try again later or download this file manually at ú.Údownload_warningz	&confirm=zcontent-dispositionzfilename="(.+)")Úsplitr–   ÚSessionrœ   r5   ÚcontentÚlowerÚConnectionErrorr   ÚcookiesÚitemsÚ
startswithr›   ÚreÚfindall)	ÚlinkÚfile_idÚ	drive_urlÚfilenameÚsessionr?   r   ÚvÚcds	            r   Úget_google_drive_file_infor¾   Þ   s¥  € ð& �jŠj˜ÑÔ Ô"×(Ò(¨Ñ1Ô1°!Ô4€GØKÀ'ÐKÐK€IØ€Hõ 
Ô	Ñ	Ô	ð <˜wØ—;’;˜y°�;Ñ6Ô6ˆØ�s 8Ô#3×#9Ò#9Ñ#;Ô#;Ñ<Ô<Ð<Ð<Ý!Ýð [ØSWð[ð [ð [ñ \ô \ñ]ô ]ð ]ð Ô$×*Ò*Ñ,Ô,ð 	-ð 	-‰DˆAˆqØ�|Š|Ð.Ñ/Ô/ð -Ø˜_¨˜_˜_Ñ,�	øØÔ×!Ò!Ð"7Ñ8Ô8ˆØð 	<Ý”zÐ"3°RÑ8Ô8¸Ô;ˆHð<ð <ð <ñ <ô <ð <ð <ð <ð <ð <ð <øøøð <ð <ð <ð <ð �hÐÐs   ÁCD.Ä.D2Ä5D2é   ç      ð?c	                 ó$  — |                       d¦  «        }	|	rt          | ¦  «        \  } }t          |pd¦  «        |pt          | ¦  «        z  }
dt	          | ¦  «        vr2t          | ¦  «                             ¦   «         rt          | ¦  «        }
�nº|
                     ¦   «         �s¥d|	r| nt          | ¦  «        › d|
› d�}t          j        |› d�¦  «         |
j	         
                    dd¬	¦  «         t          | ¦  «         t          |d
z   ¦  «        D �]5}	 |s|dk    rBd| z  }t          j        ddd|› d�| d|
ddddg
¦  «        j        }|dk    sJ d|› �¦   «         ‚�nd}|dk    r#t           j                             | |
|¬¦  «         nàt'          j        | ¦  «        5 }t+          t-          |                     dd¦  «        ¦  «        || ddd¬¦  «        5 }t1          |
d¦  «        5 }|D ]9}|                     |¦  «         |                     t7          |¦  «        ¦  «         Œ:	 ddd¦  «         n# 1 swxY w Y   ddd¦  «         n# 1 swxY w Y   ddd¦  «         n# 1 swxY w Y   |
                     ¦   «         r3|
                     ¦   «         j        |k    r n«|
                     ¦   «          �Œ¢# t@          $ rˆ}|dk    r/tC          ¦   «         s!tE          tG          d| › d�¦  «        ¦  «        |‚||k    r!tE          tG          d| › d �¦  «        ¦  «        |‚t          j$        d!|d
z   › d"|› d#| › d�¦  «         Y d}~�Œ/d}~ww xY w|rÀ|
                     ¦   «         r®|
j%        d$v r§dd%l&m'} |p|
j	         (                    ¦   «         } ||
¦  «        rtS          |
||¬&¦  «        }nL|
j%        d'v rCt          j        d(|
› d)|› d�¦  «         t          j        d*|
j%        d+k    rd,nd-|
d.|gd¬/¦  «         |r|
                     ¦   «          |S dS dS dS )0aI  
    Downloads files from a URL, with options for retrying, unzipping, and deleting the downloaded file.

    Args:
        url (str): The URL of the file to be downloaded.
        file (str, optional): The filename of the downloaded file.
            If not provided, the file will be saved with the same name as the URL.
        dir (str, optional): The directory to save the downloaded file.
            If not provided, the file will be saved in the current working directory.
        unzip (bool, optional): Whether to unzip the downloaded file. Default: True.
        delete (bool, optional): Whether to delete the downloaded file after unzipping. Default: False.
        curl (bool, optional): Whether to use curl command line tool for downloading. Default: False.
        retry (int, optional): The number of times to retry the download in case of failure. Default: 3.
        min_bytes (float, optional): The minimum number of bytes that the downloaded file should have, to be considered
            a successful download. Default: 1E0.
        progress (bool, optional): Whether to display a progress bar during the download. Default: True.

    Example:
        ```python
        from ultralytics.utils.downloads import safe_download

        link = "https://ultralytics.com/assets/bus.jpg"
        path = safe_download(link)
        ```
    zhttps://drive.google.com/r«   ú://zDownloading z to 'ú'ra   T©Úparentsrˆ   r{   r   ÚsSÚcurlz-#ú-ÚLz-oz--retryÚ3z-CzCurl return value Útorch)rn   r“   ÚBi   )r¤   rc   re   rd   Ú
unit_scaleÚunit_divisorÚwbNu   â�Œ  Download failure for z. Environment is not online.z. Retry limit reached.u"   âš ï¸� Download failure, retrying r|   r’   )r   r^   ú.tarú.gz)ru   )rJ   rH   rn   )rÐ   rÑ   r}   r`   ÚtarrÐ   ÚxfÚxfzz--directory)r=   )*r´   r¾   r   r   r5   rZ   r   r   rF   r   Úmkdirr¨   ÚrangeÚ
subprocessÚrunÚ
returncoderË   ÚhubÚdownload_url_to_filer   r:   r	   rš   Ú	getheaderÚopenrj   Úupdater�   r~   ÚstatÚst_sizerG   r4   r   r±   r   r…   r   rf   ru   r†   r�   )r<   rJ   ÚdirÚunzipÚdeleterÇ   ÚretryÚ	min_bytesrn   ÚgdriverL   rc   ÚiÚsr¢   Úmethodr?   ÚpbarÚf_openedr£   Úeru   Ú	unzip_dirs                          r   Úsafe_downloadrî     sj  € ðD �^Š^Ð7Ñ8Ô8€FØð 4Ý.¨sÑ3Ô3‰	ˆˆTåˆSˆZ�CÑÔ˜DÐ1¥H¨S¡M¤MÑ2€AØ•C˜‘H”HÐÐ¥ c¡¤×!2Ò!2Ñ!4Ô!4ÐÝ�‰IŒIˆ‰Ø�YŠY‰[Œ[ñ $^ØJ VÐ?˜c˜cµ¸3±´ÐJÐJÀaÐJÐJÐJˆÝŒ�t�L�L�LÑ!Ô!Ð!Ø	Œ�Š˜t¨dˆÑ3Ô3Ð3Ý˜ÑÔÐÝ�u˜q‘yÑ!Ô!ð 	^ñ 	^ˆAð^Øð ;˜1˜qš5˜5Ø H Ñ-�AÝ"œ¨°°h¸!°h°h°hÀÀTÈ1ÈiÐY\Ð^bÐdgÐ'hÑiÔiÔt�AØ š6˜6˜6Ð#;¸Ð#;Ð#;™6œ6˜6™6à$�FØ Ò(Ð(Ýœ	×6Ò6°s¸AÈÐ6ÑQÔQÐQÐQå$œ_¨SÑ1Ô1ð 	;°X½tÍ#Èh×N`ÒN`ÐaqÐstÑNuÔNuÑJvÔJvØIMØPXÈLØILØOSØQUð@Wñ @Wô @Wð 	;ð
 [_Ý!% a¨¡¤ð ;°(Ø,4ð !;ð !; DØ$,§N¢N°4Ñ$8Ô$8Ð$8Ø$(§K¢Kµ°D±	´	Ñ$:Ô$:Ð$:Ð$:ð!;ð;ð ;ð ;ñ ;ô ;ð ;ð ;ð ;ð ;ð ;ð ;øøøð ;ð ;ð ;ð ;ð	;ð 	;ð 	;ñ 	;ô 	;ð 	;ð 	;ð 	;ð 	;ð 	;ð 	;øøøð 	;ð 	;ð 	;ð 	;ð 	;ð 	;ð 	;ñ 	;ô 	;ð 	;ð 	;ð 	;ð 	;ð 	;ð 	;øøøð 	;ð 	;ð 	;ð 	;ð —8’8‘:”:ð Ø—v’v‘x”xÔ'¨)Ò3Ð3Ø˜Ø—H’H‘J”J�JùøÝð ^ð ^ð ^Ø˜’6�6¥)¡+¤+�6Ý)­&Ð1oÈcÐ1oÐ1oÐ1oÑ*pÔ*pÑqÔqÐwxÐxØ˜%’Z�ZÝ)­&Ð1iÈcÐ1iÐ1iÐ1iÑ*jÔ*jÑkÔkÐqrÐrÝ”Ð\ÀAÈÁEÐ\Ð\ÈEÐ\Ð\ÐTWÐ\Ð\Ð\Ñ]Ô]Ð]Ð]Ð]Ð]Ð]Ñ]øøøøð^øøøð ð �—’‘”ð  ¤Ð,GÐ GÐ GØ&Ð&Ð&Ð&Ð&Ð&à�_˜AœH×-Ò-Ñ/Ô/ˆ	Øˆ:�a‰=Œ=ð 	tÝ"¨°	ÀHÐMÑMÔMˆIˆIØŒX˜Ð(Ð(ÝŒKÐ: QÐ:Ð:¨IÐ:Ð:Ð:Ñ;Ô;Ð;ÝŒN˜E¨1¬8°vÒ+=Ð+= 4 4À5È!È]Ð\eÐfÐnrÐsÑsÔsÐsØð 	Ø�HŠH‰JŒJˆJØÐðð ð ð Ð GÐ GsŒ   ÄB	J5Æ 8I!ÇI
Ç)=H3	È'I
È3H7È7I
È:H7È;I
È>I!É
IÉI!ÉIÉI!ÉJ5É!I%	É%J5É(I%	É)4J5ÊJ5Ê5
MÊ?A=MÍMÚlatestc                 óp  — |dk    rd|› �}d| › d|› �}t          j        |¦  «        }|j        dk    r!|j        dk    r|rt          j        |¦  «        }|j        dk    r+t	          j        d|› d|j        › d	|j        › �¦  «         d
g fS |                     ¦   «         }|d         d„ |d         D ¦   «         fS )aÇ  
    Retrieve the specified version's tag and assets from a GitHub repository. If the version is not specified, the
    function fetches the latest release assets.

    Args:
        repo (str, optional): The GitHub repository in the format 'owner/repo'. Defaults to 'ultralytics/assets'.
        version (str, optional): The release version to fetch assets from. Defaults to 'latest'.
        retry (bool, optional): Flag to retry the request in case of a failure. Defaults to False.

    Returns:
        (tuple): A tuple containing the release tag and a list of asset names.

    Example:
        ```python
        tag, assets = get_github_assets(repo='ultralytics/assets', version='latest')
        ```
    rï   ztags/zhttps://api.github.com/repos/z
/releases/r1   zrate limit exceededu'   âš ï¸� GitHub assets check failure for r‘   r’   r   Útag_namec                 ó   — g | ]
}|d          ‘ŒS rU   r   )r   rX   s     r   r   z%get_github_assets.<locals>.<listcomp>  s   € Ð@Ð@Ð@¨A˜a œiÐ@Ð@Ð@r   Úassets)r–   rœ   r˜   r™   r   r…   Újson)ÚrepoÚversionrä   r<   r¢   r£   s         r   Úget_github_assetsr÷   b  sã   € ð& �(ÒÐØ#˜'Ð#Ð#ˆØ
C¨$Ð
CÐ
C¸'Ð
CÐ
C€CÝŒ�SÑÔ€AØ„}˜ÒÐ ¤Ð,AÒ AÐ AÀeÐ AÝŒL˜ÑÔˆØ„}˜ÒÐÝŒÐbÀÐbÐbÈÌÐbÐbÐXYÔX`ÐbÐbÑcÔcÐcØ�2ˆvˆØ�6Š6‰8Œ8€DØ�
ÔÐ@Ð@°°h´Ð@Ñ@Ô@Ð@Ð@r   úv0.0.0c                 ó:  — ddl m} t          | ¦  «        } t          j        | ¦  «        } t          |                      ¦   «                              dd¦  «        ¦  «        } |                      ¦   «         rt          | ¦  «        S |d         | z                       ¦   «         rt          |d         | z  ¦  «        S t          t          j
        t          | ¦  «        ¦  «        ¦  «        j        }d|› d�}t          | ¦  «                             d¦  «        rŒt          | ¦  «                             d	d
¦  «        }t          |¦  «        } t          | ¦  «                             ¦   «         r(t          j        dt#          |¦  «        › d| › �¦  «         n�t%          d|| ddœ|¤Ž np|t&          k    r"|t(          v rt%          d|› d|› d|› �| ddœ|¤Ž nCt+          ||¦  «        \  }}	|	st+          |¦  «        \  }}	||	v rt%          d|› d|› d|› �| ddœ|¤Ž t          | ¦  «        S )a!  
    Attempt to download a file from GitHub release assets if it is not found locally. The function checks for the file
    locally first, then tries to download it from the specified GitHub repository release.

    Args:
        file (str | Path): The filename or file path to be downloaded.
        repo (str, optional): The GitHub repository in the format 'owner/repo'. Defaults to 'ultralytics/assets'.
        release (str, optional): The specific release version to be downloaded. Defaults to 'v0.0.0'.
        **kwargs (dict): Additional keyword arguments for the download process.

    Returns:
        (str): The path to the downloaded file.

    Example:
        ```python
        file_path = attempt_download_asset('yolov5s.pt', repo='ultralytics/assets', release='latest')
        ```
    r   )ÚSETTINGSrÃ   r   Úweights_dirzhttps://github.com/z/releases/download)zhttp:/zhttps:/z:/rÂ   zFound z locally at g     jø@)r<   rJ   rå   r|   Nr   )Úultralytics.utilsrú   r5   r
   Úcheck_yolov5u_filenamer   ÚstripÚreplacer~   r   ÚunquoterV   r´   r   rZ   r   rF   r   rî   ÚGITHUB_ASSETS_REPOÚGITHUB_ASSETS_NAMESr÷   )
rJ   rõ   ÚreleaseÚkwargsrú   rV   Údownload_urlr<   Útagró   s
             r   Úattempt_download_assetr  ‚  sL  € ð& +Ð*Ð*Ð*Ð*Ð*õ ˆt‰9Œ9€DÝÔ(¨Ñ.Ô.€DÝ�—
’
‘”×$Ò$ S¨"Ñ-Ô-Ñ.Ô.€DØ‡{‚{�}„}ð Ý�4‰yŒyÐØ
�=Ô
! DÑ
(×	0Ò	0Ñ	2Ô	2ð Ý�8˜MÔ*¨TÑ1Ñ2Ô2Ð2õ •E”M¥# d¡)¤)Ñ,Ô,Ñ-Ô-Ô2ˆØE¨TÐEÐEÐEˆÝˆt‰9Œ9×ÒÐ 5Ñ6Ô6ð 	fÝ�d‘)”)×#Ò# D¨%Ñ0Ô0ˆCÝ˜D‘>”>ˆDÝ�D‰zŒz×!Ò!Ñ#Ô#ð KÝ”ÐG¥Y¨s¡^¤^ÐGÐGÀÐGÐGÑHÔHÐHÐHåÐJ #¨D¸CÐJÐJÀ6ÐJÐJÐJÐJàÕ'Ò'Ð'¨DÕ4GÐ,GÐ,GÝÐe Ð@Ð@°Ð@Ð@¸$Ð@Ð@ÀtÐWZÐeÐeÐ^dÐeÐeÐeÐeõ ,¨D°'Ñ:Ô:‰KˆC�Øð 6Ý/°Ñ5Ô5‘��VØ�vˆ~ˆ~ÝÐe \Ð"@Ð"@°CÐ"@Ð"@¸$Ð"@Ð"@ÀtÐWZÐeÐeÐ^dÐeÐeÐeå�4‰yŒyÐr   r{   c           
      óî  ‡‡‡‡‡— t          |¦  «        }|                     dd¬¦  «         ‰dk    rŠt          ‰¦  «        5 }|                     ˆˆˆˆˆfd„t	          | t          |¦  «        ¦  «        ¦  «         |                     ¦   «          |                     ¦   «          ddd¦  «         dS # 1 swxY w Y   dS t          | t          t           f¦  «        r| gn| D ]}t          ||‰‰‰‰¬¦  «         ŒdS )a¸  
    Downloads files from specified URLs to a given directory. Supports concurrent downloads if multiple threads are
    specified.

    Args:
        url (str | list): The URL or list of URLs of the files to be downloaded.
        dir (Path, optional): The directory where the files will be saved. Defaults to the current working directory.
        unzip (bool, optional): Flag to unzip the files after downloading. Defaults to True.
        delete (bool, optional): Flag to delete the zip files after extraction. Defaults to False.
        curl (bool, optional): Flag to use curl for downloading. Defaults to False.
        threads (int, optional): Number of threads to use for concurrent downloads. Defaults to 1.
        retry (int, optional): Number of retries in case of download failure. Defaults to 3.

    Example:
        ```python
        download('https://ultralytics.com/assets/example.zip', dir='path/to/dir', unzip=True)
        ```
    TrÄ   r{   c           
      óP   •— t          | d         | d         ‰‰‰‰‰dk    ¬¦  «        S )Nr   r{   )r<   rá   râ   rã   rÇ   rä   rn   )rî   )rX   rÇ   rã   rä   Úthreadsrâ   s    €€€€€r   ú<lambda>zdownload.<locals>.<lambda>Ð  s8   ø€ �-Ø˜!œ ! A¤$¨e¸FÈÐUZÐelÐpqÒeqðsñ sô s€ r   N)r<   rá   râ   rã   rÇ   rä   )r   rÕ   r   ÚmapÚzipr   ÚcloseÚjoinÚ
isinstancer5   rî   )	r<   rá   râ   rã   rÇ   r
  rä   ÚpoolÚus	     `````  r   Údownloadr  ¸  sn  øøøøø€ õ& ˆs‰)Œ)€CØ‡I‚I�d T€IÑ*Ô*Ð*Ø�‚{€{Ý˜Ñ Ô ð 	 DØ�HŠHðsð sð sð sð sð sð sð så�C� ™œÑ%Ô%ñ'ô 'ð 'ð �JŠJ‰LŒLˆLØ�IŠI‰KŒKˆKð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	õ % S­3µ¨+Ñ6Ô6Ð?�#��¸Cð 	^ð 	^ˆAÝ˜a S°¸fÈ4ÐW\Ð]Ñ]Ô]Ð]Ð]ð	^ð 	^s   ÁA!B/Â/B3Â6B3)T)rA   )TrA   T)NrA   FT)rŽ   r�   T)NNTFFr¿   rÀ   T)r   rï   F)r   rø   )%r2   rµ   r�   r×   Ú	itertoolsr   Úmultiprocessing.poolr   Úpathlibr   Úurllibr   r   r–   rË   rü   r   r	   r
   r   r   r   r   r  r  ÚGITHUB_ASSETS_STEMSr@   rM   rr   r�   r¨   r¾   rî   r÷   r  Úcwdr  r   r   r   ú<module>r     s¬  ðð Ð Ð Ð Ø 	€	€	€	Ø €€€Ø Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø +Ð +Ð +Ð +Ð +Ð +Ø Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ð !Ð !à €€€Ø €€€à ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ Zð *Ð ØlÐl¸ÐlÑlÔlØaÐa¸WÐaÑaÔañbàGÐGÐ1FÐGÑGÔGñHð :Ð9°5Ð9Ñ9Ô9ñ:ð 4Ð3¨dÐ3Ñ3Ô3ñ	4ð
 8Ð7°$Ð7Ñ7Ô7ñ8ð 7Ð6°Ð6Ñ6Ô6ñ7ð 'Ð'ñ(Ð ð BÐAÐ-@ÐAÑAÔAÐ ðð ð ð ð:ð ð ð ð4$ð $ð $ð $ðN=ð =ð =ð =ð@ð ð ð ðD$ð $ð $ðP ØØØØØØØðZð Zð Zð ZðzAð Að Að Að@3ð 3ð 3ð 3ðl �d”h‘j”j¨°UÀÐPQÐYZð ^ð ^ð ^ð ^ð ^ð ^r   