a
    ÿëÞhâ  ã                   @   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   sp   |   d| j› d¡ t| j| jƒ}t ¡ }tj| j|f|d d}| 	¡  z| 
||¡W | ¡  S | ¡  0 d S )Nú[z] Downloading from BunnyCDNZ_bunnycdn_ping_data)ÚtargetÚargsÚkwargs)Ú	to_screenÚFD_NAMEr   ÚydlÚparamsÚ	threadingÚEventÚThreadÚping_threadÚstartÚreal_downloadÚset)ÚselfÚfilenameZ	info_dictÚfdÚ
stop_eventr   © r   úO/mnt/pikpak/tmp/myenv/lib/python3.9/site-packages/yt_dlp/downloader/bunnycdn.pyr      s    þzBunnyCdnFD.real_downloadc                 C   sâ   d}d}d}d}	|  |¡sÞ|	|7 }	|	tt ¡ dƒ }
t |› d|› d|
› d|› d|› 	 ¡ ¡ ¡ }|› d|› d|
› d	|› d
|› 	}z| j t	||d¡ 
¡  W q tyÚ } z$|  d| j› d|› ¡ W Y d }~qd }~0 0 q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!   ÚsecretZ
context_idZping_intervalÚresZpausedÚcurrent_timeÚtimeZmd5_hashZ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   Z
networkingr   Znetworking.exceptionsr   r   r   r   r   r   Ú<module>   s   