o
    ˆ¬iâ  ã                   @   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
 G dd	„ d	eƒZdS )
é    Né   )ÚFileDownloader)ÚHlsFDé   )ÚRequest)Únetwork_exceptionsc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
BunnyCdnFDz”
    Downloads from BunnyCDN with required pings
    Note, this is not a part of public API, and will be removed without notice.
    DO NOT USE
    c                 C   sl   |   d| j› d¡ t| j| jƒ}t ¡ }tj| j|f|d d}| 	¡  z| 
||¡W | ¡  S | ¡  w )Nú[z] Downloading from BunnyCDNÚ_bunnycdn_ping_data)ÚtargetÚargsÚkwargs)Ú	to_screenÚFD_NAMEr   ÚydlÚparamsÚ	threadingÚEventÚThreadÚping_threadÚstartÚreal_downloadÚset)ÚselfÚfilenameÚ	info_dictÚfdÚ
stop_eventr   © r   úN/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/downloader/bunnycdn.pyr      s   zBunnyCdnFD.real_downloadc                 C   sî   d}d}d}d}	|  |¡su|	|7 }	|	tt ¡ dƒ }
t |› d|› d|
› d|› d|› 	 ¡ ¡ ¡ }|› d|› d|
› d	|› d
|› 	}z| j t	||d¡ 
¡  W n tym } z|  d| j› d|› ¡ W Y d }~nd }~ww |  |¡rd S d S )Nr   i8  Úfalser   é   Ú_z?hash=z&time=z&paused=z&resolution=)Úheadersr	   z] Ping failed: )ÚwaitÚroundÚrandomÚhashlibÚmd5ÚencodeÚ	hexdigestr   Úurlopenr   Úreadr   r   r   )r   r   Úurlr#   ÚsecretÚ
context_idÚping_intervalÚresÚpausedÚcurrent_timeÚtimeÚmd5_hashÚping_urlÚer   r   r   r       s    
. $€ÿ÷zBunnyCdnFD.ping_threadN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    r   )r'   r&   r   Úcommonr   Ú r   Ú
networkingr   Únetworking.exceptionsr   r   r   r   r   r   Ú<module>   s    