U
    7sgŒ  ã                   @   sh   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 d dlmZ dd„ ZdS )	é    N)ÚVar)Ú	StreamBot)Ú
humanbytes)Úget_file_ids)ÚInvalidHashc                 Ã   s6  t tttjƒt| ƒƒI d H }|jd d… |krbt d|› d|jd d… › ¡ t d| › ¡ t‚t	j
 tj|› t| ƒ› ¡}t|j d¡d  ¡ ƒdkrt d¡4 I d H šH}d	 |j¡}|j d¡d  ¡ }| ¡ I d H  d
|¡||j|f }W 5 Q I d H R X n,t|j d¡d  ¡ ƒdkrŒt d¡4 I d H šH}d |j¡}|j d¡d  ¡ }| ¡ I d H  d
|¡||j|f }W 5 Q I d H R X n¦t d¡4 I d H šˆ}t ¡ 4 I d H šf}| |¡4 I d H šB}	d |j¡}tt|	j d¡ƒƒ}
| ¡ I d H ||j||
f }W 5 Q I d H R X W 5 Q I d H R X W 5 Q I d H R X |S )Né   zlink hash: z - z#Invalid hash for message with - ID ú/r   ÚvideozWebStreamer/template/req.htmlzWatch {}ÚtagÚaudioz	Listen {}zWebStreamer/template/dl.htmlzDownload {}zContent-Length)r   r   Úintr   ÚBIN_CHANNELÚ	unique_idÚloggingÚdebugr   ÚurllibÚparseÚurljoinÚURLÚstrÚ	mime_typeÚsplitÚstripÚaiofilesÚopenÚformatÚ	file_nameÚreadÚreplaceÚaiohttpÚClientSessionÚgetr   Úheaders)Ú
message_idÚsecure_hashZ	file_dataÚsrcÚrÚheadingr
   ÚhtmlÚsÚuÚ	file_size© r,   ú@/opt/bot/vods_filmes/script/WebStreamer/utils/render_template.pyÚrender_page   s.     64Lr.   )Úurllib.parser   r   r   r   ZWebStreamer.varsr   ÚWebStreamer.botr   Ú WebStreamer.utils.human_readabler   Z!WebStreamer.utils.file_propertiesr   ÚWebStreamer.server.exceptionsr   r.   r,   r,   r,   r-   Ú<module>   s   