a
    >xd                     @   s  d Z ddlmZ ddlZddlZddlmZ ddlZddlZddl	m
Z
 ddlZddlmZ ddlmZmZ eeZeed Zd	Zejd
eZe dZejdeZe de de de de de de de ddZee d d ee d d d d d ee d d ee d d dZeddd Zedd!d"Zeed#d$d%Zeedd&d'd(Z ddd)d*Z!edd+d,Z"edd-d.Z#e$dd/d0Z%dS )1zChromium download module.    )BytesION)Path)ZipFile)tqdm)__chromium_revision____pyppeteer_home__zlocal-chromiumzhttps://storage.googleapis.comZPYPPETEER_DOWNLOAD_HOSTz/chromium-browser-snapshotsZPYPPETEER_CHROMIUM_REVISIONz/Linux_x64/z/chrome-linux.zipz/Mac/z/chrome-mac.zipz/Win/z/chrome-win32.zipz	/Win_x64/)linuxmacwin32win64zchrome-linuxchromez
chrome-maczChromium.appZContentsMacOSZChromiumzchrome-win32z
chrome.exe)returnc                   C   sh   t jdrdS t jdr dS t jdsDt jdsDt jdrVt jdkrRdS d	S td
t j dS )z*Get current platform name by short string.r   darwinr	   winZmsysZcygir   r
   zUnsupported platform: N)sysplatform
startswithmaxsizeOSError r   r   U/var/www/html/Ranjet/env/lib/python3.9/site-packages/pyppeteer/chromium_downloader.pycurrent_platform.   s    


r   c                   C   s
   t t  S )zGet chromium download url.)downloadURLsr   r   r   r   r   get_url=   s    r   )urlr   c                 C   s   t d t  t }|jd| dd}zt|jd }W n tt	t
fyZ   d}Y n0 t|d}t }|dD ]}|| |t| qv|  W d	   n1 s0    Y  t d
 |S )zDownload data from url.z9start chromium download.
Download may take a few minutes.GETF)preload_contentzcontent-lengthr   )totali (  Nz
chromium download done.)loggerwarningurllib3disable_warningsPoolManagerrequestintheadersKeyError
ValueErrorAttributeErrorr   r   streamwriteupdatelenclose)r   httpdatatotal_lengthZprocess_bar_datachunkr   r   r   download_zipB   s     




&
r4   )r0   pathr   c           	      C   sv  t  dkrddl}ddl}|d }| s6|jdd |d}||   W d   n1 sd0    Y  |dst	d	| d
|j
dt|gt||j|jd}|jdkrt|j  t	d| dt  r| r|  n8t| }|t| W d   n1 s0    Y  t }| s@td|| jtjB tjB tjB  td|  dS )zExtract zipped data to path.r	   r   Nz
chrome.zipT)parentswbZunzipz6Failed to automatically extract chromium.Please unzip z
 manually.)cwdstdoutstderrzFailed to unzip .zFailed to extract chromium.zchromium extracted to: )r   
subprocessshutilexistsmkdiropenr+   getvaluewhichr   runstrPIPESTDOUT
returncoder   errorr9   decodechromium_executableunlinkr   
extractallIOErrorchmodstatst_modeS_IXOTHS_IXGRPS_IXUSRr    )	r0   r5   r<   r=   zip_pathfproczfZ	exec_pathr   r   r   extract_zipb   s@    
,





.
rX   c                   C   s   t tt tt  dS )zDownload and extract chromium.N)rX   r4   r   DOWNLOADS_FOLDERREVISIONr   r   r   r   download_chromium   s    r[   c                   C   s   t d t S )zP[Deprecated] miss-spelled function.

    Use `chromium_executable` instead.
    zN`chromium_excutable` function is deprecated. Use `chromium_executable instead.)r   r    rJ   r   r   r   r   chromium_excutable   s    r\   c                   C   s
   t t  S )z$Get path of the chromium executable.)chromiumExecutabler   r   r   r   r   rJ      s    rJ   c                   C   s
   t   S )z,Check if chromium is placed at correct path.)rJ   r>   r   r   r   r   check_chromium   s    r^   )&__doc__ior   loggingospathlibr   rO   r   zipfiler   r!   r   Z	pyppeteerr   r   	getLogger__name__r   rY   ZDEFAULT_DOWNLOAD_HOSTenvirongetZDOWNLOAD_HOSTZBASE_URLrZ   r   r]   rD   r   r   r4   rX   r[   r\   rJ   boolr^   r   r   r   r   <module>   sX   

	 $