U
    $P‘f˜  ã                   @   sœ   d dl mZ d dlZd dlZd dlZ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	„ Zd
d„ Zdd„ Zefdd„ZdS )é    )Úunicode_literalsN)Úzipimporteré   )Úcompat_realpath)Úencode_compat_str)Ú__version__c                 C   sÐ   ddl m} t| tƒst‚tt|d ƒƒd d d d }dtt|dƒ|d |d ƒ  	¡ }|d t|ƒ d | }d	}||| ƒ 
¡  	¡ 7 }|t|ƒd d
 k r¤dS d|t|ƒd  d d  d | }||kS )Nr   )Úsha256é   é   r   z%xé   ó   0s&   3031300d060960864801650304020105000420é   Fs   0001é   s   ffs   00)Úhashlibr   Ú
isinstanceÚbytesÚAssertionErrorÚlenÚbinÚpowÚintÚencodeÚ	hexdigest)ÚmessageÚ	signatureÚkeyr   Z	byte_sizeZasn1Úexpected© r   ú5/tmp/pip-unpacked-wheel-7zdooeg3/youtube_dl/update.pyÚ
rsa_verify   s     "$r   c              	   C   s¶  d}|d }|d }d}t tƒ  d¡tƒs@ttdƒs@| dƒ dS z| |¡ ¡  d	¡ 	¡ }W n2 t
k
rŽ   |r€| tt ¡ ƒƒ | d
ƒ Y dS X |tkr¬| dt d ƒ dS z"| |¡ ¡  d	¡}t |¡}W n4 t
k
r   |rô| tt ¡ ƒƒ | dƒ Y dS X d|kr| dƒ dS |d }	|d= ttj|dd d	¡|	|ƒsR| dƒ dS |d }
dd„ }|tƒ||
ƒkr„| dt ƒ dS | d|
 d ƒ |d |
 }t| |d ƒ tttdƒrÂtjntjd ƒ}t |tj¡sî| d| ƒ dS ttdƒr¨|}tj |¡}t |tj¡s*| d| ƒ dS z&| |d d ¡}| ¡ }| ¡  W n: ttfk
rŠ   |r|| tt ¡ ƒƒ | dƒ Y dS X t  !|¡ "¡ }||d d kr¸| dƒ dS z(t|d  d!ƒ}| #|¡ W 5 Q R X W n: ttfk
r   |r| tt ¡ ƒƒ | d"ƒ Y dS X zLtj $|d#¡}t% |d$¡}| #d%|||
f ¡ W 5 Q R X t& '|g¡ W dS  ttfk
r¢   |r”| tt ¡ ƒƒ | d&ƒ Y dS X nt tƒ  d¡tƒrªz&| |d' d ¡}| ¡ }| ¡  W n: ttfk
r   |r| tt ¡ ƒƒ | dƒ Y dS X t  !|¡ "¡ }||d' d krJ| dƒ dS z$t|d!ƒ}| #|¡ W 5 Q R X W n: ttfk
r¨   |rš| tt ¡ ƒƒ | d&ƒ Y dS X | d(ƒ dS ))zCUpdate the program file with the latest version from the repositoryzhttps://yt-dl.org/update/ZLATEST_VERSIONzversions.json)lE   “~MB™=5qÇEyG ½œ(d]6m_åp¿a®@0T³b*,!Ócé8OâsÍ6Äs·D”`‘W¤ä5WÆOdr1lQac je<1BOÔdÿC…N©všo[¸R\i^TEMè2g¾#î]0k[9_˜VØ~S 69k	 i  Ú
__loader__ÚfrozenzuIt looks like you installed youtube-dl with a package manager, pip, setup.py or a tarball. Please use that to update.Nzutf-8z>ERROR: can't find the current version. Please try again later.zyoutube-dl is up-to-date (ú)z:ERROR: can't obtain versions info. Please try again later.r   z>ERROR: the versions file is not signed or corrupted. Aborting.T)Ú	sort_keysz8ERROR: the versions file signature is invalid. Aborting.Zlatestc                 S   s   t tt|  d¡ƒƒS )NÚ.)ÚtupleÚmapr   Úsplit)Úversion_strr   r   r   Úversion_tupleL   s    z"update_self.<locals>.version_tuplezyoutube-dl is up to date (%s)zUpdating to version z ...Úversionsr   z!ERROR: no write permissions on %sÚexez(ERROR: unable to download latest versionr   z9ERROR: the downloaded file hash does not match. Aborting.z.newÚwbz&ERROR: unable to write the new versionzyoutube-dl-updater.batÚwz×
@echo off
echo Waiting for file handle to be closed ...
ping 127.0.0.1 -n 5 -w 1000 > NUL
move /Y "%s.new" "%s" > NUL
echo Updated youtube-dl to version %s.
start /b "" cmd /c del "%%~f0"&exit /b"
                
z*ERROR: unable to overwrite current versionr   z>Updated youtube-dl. Restart youtube-dl to use the new version.)(r   ÚglobalsÚgetr   ÚhasattrÚsysÚopenÚreadÚdecodeÚstripÚ	Exceptionr   Ú	tracebackÚ
format_excr   ÚjsonÚloadsr   Údumpsr   Úprint_notesr   Ú
executableÚargvÚosÚaccessÚW_OKÚpathÚdirnameÚcloseÚIOErrorÚOSErrorr   r   r   ÚwriteÚjoinÚioÚ
subprocessÚPopen)Ú	to_screenÚverboseÚopenerZ
UPDATE_URLZVERSION_URLZJSON_URLZUPDATES_RSA_KEYZ
newversionZversions_infor   Ú
version_idr)   ÚversionÚfilenamer+   Ú	directoryZurlhZ
newcontentZnewcontent_hashÚoutfZbatZbatfiler   r   r   Úupdate_self    sØ    
 ù	rT   c                 C   s8   g }t |  ¡ ƒD ]"\}}||kr| | dg ¡¡ q|S )NÚnotes)ÚsortedÚitemsÚextendr/   )r*   ÚfromVersionrU   ÚvZvdatar   r   r   Ú	get_notes±   s
    r[   c                 C   s,   t ||ƒ}|r(| dƒ |D ]}| |ƒ qd S )NzPLEASE NOTE:)r[   )rL   r*   rY   rU   Znoter   r   r   r<   ¹   s
    
r<   )Ú
__future__r   rI   r9   r7   r   r?   rJ   r1   Ú	zipimportr   Úcompatr   Úutilsr   rP   r   r   rT   r[   r<   r   r   r   r   Ú<module>   s     