
    vi                     (   % S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKrS SKrS SKJr  S SKJrJr  S\4S jrS\" 5       0r\\\4   \S'   S\R0                  ;   a  \" \R0                  S   R5                  5       5      S :  a  \R0                  S   R5                  5       r\R8                  " S	\5      r\bt  \R<                  " \R>                  \RA                  S
5      \!" \RA                  S5      5      S\RA                  S5      \RA                  S5      5        \RD                  \l        \RF                  r$0 SSS4S\S\\\4   S\\   S\\RJ                     S\&S\4S jjr'SS\S\\   S\\RJ                     S\4S jjr(g)    N)Mapping)AnyOptionalreturnc                      [         R                  " SSS5      n Sn[         R                  R                  5       nXU -
  R                  S-  -   nSU SU S3$ )	z3Disguise as browser to circumvent website blocking i        }      z-Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:z.0) Gecko/20100101 Firefox/z.0)datetimedatetodaydays)baseDatebaseVersionnowDate
nowVersions       &/app/qBittorrent/data/nova3/helpers.pygetBrowserUserAgentr   /   s^     }}T1b)HKmm!!#G8!3 9 9R ?@J::,Fablammopp    z
User-Agentheaders
sock_proxyzL^(?:(?P<username>[^:]+):(?P<password>[^@]+)@)?(?P<host>[^:]+):(?P<port>\w+)$hostportTusernamepasswordurlcustom_headersrequest_datassl_contextunescape_html_entitiesc                    [         R                  R                  X0 [        EUE5      n [         R                  R	                  XSS9nUR                  5       nUSS S:X  aL  [        R                  " U5       n	[        R                  " U	S9 n
U
R                  5       nSSS5        SSS5        S	n UR!                  S
S5      R#                  SS5      S   nUR'                  US5      nU(       a  [(        R*                  " U5      nU$ ! [         R
                  R                   a/  n[        SUR                   3[        R                  S9   SnAgSnAff = f! , (       d  f       N= f! , (       d  f       N= f! [$         a     Nf = f)z/Return the content of the url page as a string contextzConnection error: )fileN       fileobjzutf-8zContent-Typezcharset=   replace)urllibrequestRequestr   urlopenerrorURLErrorprintreasonsysstderrreadioBytesIOgzipGzipFile	getheadersplit
IndexErrordecodehtmlunescape)r   r   r   r    r!   r.   responseerrnodatacompressedStreamgzippercharsetdataStrs                r   retrieve_urlrI   P   sE    nn$$S8U78Un8UVG>>))')G --/D BQx;ZZ!14==IY3Z^e<<>D 4[ G$$^R8>>z1MaP kk'9-G--(N- <<   "5<<.1

C 4[3Z  sM   D 6E&EE&/%E7 E#%EE
E#	E&&
E47
FFrefererc                 x   [         R                  R                  U [        S9nUb  UR	                  SU5        [         R                  R                  X2S9nUR                  5       nUSS S:X  aL  [        R                  " U5       n[        R                  " US9 nUR                  5       nSSS5        SSS5        [        R                  " 5       u  p[        R                  " US5       n
U
R                  U5        SSS5        U	 S	U  3$ ! , (       d  f       Ne= f! , (       d  f       Nn= f! , (       d  f       N7= f)
zUDownload file at url and write it to a file, return the path to the file and the url )r   NrJ   r#   r'   r(   r)   wb )r-   r.   r/   r   
add_headerr0   r7   r8   r9   r:   r;   tempfilemkstemposfdopenwrite)r   rJ   r    r.   rB   rD   rE   rF   
fileHandlepathr%   s              r   download_filerV   o   s     nn$$S'$:G9g.~~%%g%CH==?D BQx;ZZ!14==IY3Z^e<<>D 4[  '')J	:t	$

4 
% V1SE? 4[3Z
 
%	$s0   DD	*D(D+	
D	D
D(+
D9)NN))r   r:   r@   r8   rQ   resocketsockssslr5   rO   urllib.errorr-   urllib.requestcollections.abcr   typingr   r   strr   r   dict__annotations__environlenstrip	proxy_strmatchmsetdefaultproxyPROXY_TYPE_SOCKS5groupint
socksocketrA   htmlentitydecode
SSLContextboolrI   rV    r   r   <module>rq      s  <    	 	 	   
 
    #  qS q  ()<)>?c3h ? 2::#bjj&>&D&D&F"G!"K

<(..0I
`	A}e55qwwv!!''&/2D!''*:MqwwWaOb	d(( ==  @Bae  PT  uy c 738+< QYZ]Q^ t|  ~A  ~L  ~L  uM   nr   ~A >s Xc] QTQ_Q_H` lo r   