
    VGh\              	         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	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mZ ddlmZmZmZmZmZmZmZmZ dd	lmZm Z m!Z!m"Z"m#Z#m$Z$ d
dddZ%e%d   Z&e%jO                         D  ci c]  \  } }|| 
 c}} Z( e	jR                  d      Z*dZ+ e	jR                  de+ d      Z,dZ-e- de& dZ.ej^                  d        Z0d Z1ej^                  d        Z2dddddddd d!Z3i e4jk                  e3      d"d#d$d%jO                         D ci c]  \  }}|d&| d' c}}d(d)d*d+d,Z6d- Z7d. Z8d/ Z9d0 Z:d7d1Z;e G d2 d3             Z< G d4 d5      Z=d6 Z>d5gZ?yc c}} w c c}}w )8    )annotationsN)	dataclass)zipimporter   )Request)	HTTPErrornetwork_exceptions)
NO_DEFAULTPopendeprecation_warningformat_field
remove_endshell_quotesystem_identifierversion_tuple)CHANNELORIGINRELEASE_GIT_HEADUPDATE_HINTVARIANT__version__zyt-dlp/yt-dlpzyt-dlp/yt-dlp-nightly-buildszyt-dlp/yt-dlp-master-builds)stablenightlymasterr   z(\d+\.)*\d+z[\da-f]{40}z7Generated from: https://(?:[^/?#]+/){3}commit/(?P<hash>)zhttps://api.github.com/repos/z	/releasesc                 &   t        t        dd      r0t        j                  } t        t        d      sd| fS t        j                  t
        j                  j                  |       k(  rt        j                   d| fS t        j                  dk(  r(t        t        j                         d         dk  rd	nd
}nkdt        j                         j                          }t        j                  dkD  }|dd dv r|sdnd
}n|dd dk(  r|sd}t        j                  d      x}r|} t        t        j                  d       | d| fS t
        j                  j                  t               } t#        t$        t&              r"dt
        j                  j)                  | d      fS t
        j                  j+                  t        j,                  d         dv rAt
        j                  j/                  t
        j                  j)                  | d            rd| fS d| fS )z#@returns (variant, executable_path)frozenF_MEIPASSpy2exe_dirdarwinr   )
      _legacy _l        r   N)x86x86_64amd64i386i686_x86aarch64_armv7lSTATICX_PROG_PATH32_exezipz..)z__main__.pyz-mz../.git/HEADsourceunknown)getattrsys
executablehasattrr   ospathdirnameplatformr   mac_vermachinelowermaxsizegetenvr   __file__
isinstance
__loader__r   joinbasenameargvexists)r;   r?   	is_64bitsstatic_exe_paths       V/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/update.py _get_variant_and_executable_pathrM   7   s    sHe$~~sJ'T>!\\RWW__T22ll^4($..\\X%#01A1A1CA1F#G(#RiXZG(**,22456Ge+Iqr{HH(1&r 	))# #%)),?"@@@&S\\401'$?EE77??8$D*k*bggll4...
''

388A;
'+@
@ggnnRWW\\$?@~d?    c                 ,    t         xs t               d   S )Nr   )r   rM    rN   rL   detect_variantrQ   [   s    ;68;;rN   c            
        t               dk7  ry t        j                  t              5  t	        j
                  g ddt        j                  j                  t        j                  j                  t                    t        j                  t        j                        \  } }}t        j                  d| j                               r| j                         cd d d        S 	 d d d        y # 1 sw Y   y xY w)Nr4   )gitz	rev-parsez--shortHEADT)textcwdstdoutstderrz	[0-9a-f]+)rQ   
contextlibsuppress	Exceptionr   runr:   r;   r<   abspathrC   
subprocessPIPEre	fullmatchstrip)rW   r'   s     rL   current_git_headrc   _   s    8#			Y	' "yy3277??277??8+DE??:??<1 <<V\\^4<<>" "
 5" " "s   B.C**C3r&   z.exez_x86.exe_macos_macos_legacy_linux_linux_aarch64_linux_armv7l)r3   win_exewin_x86_exe
darwin_exedarwin_legacy_exe	linux_exelinux_aarch64_exelinux_armv7l_exeWindowsMacOSLinux)	win32_dir
darwin_dir	linux_dirz,Auto-update is not supported for unpackaged z+ executable; Re-download the latest releasezJpy2exe is no longer supported by yt-dlp; This executable cannot be updatedzSYou cannot update when running from source code; Use git to pull the latest changeszVYou installed yt-dlp from a manual build or with a package manager; Use that to updatezGYou are using an unofficial build of yt-dlp; Build the executable again)r    r4   r5   otherc                     t         rt         S t        j                  t               t        t        rd         S d         S )Nr5   rv   )r   _NON_UPDATEABLE_REASONSgetrQ   r   rP   rN   rL   is_non_updateablerz      sB    "&&1w)TV VLSTV VrN   c                 :    t        t        t               dd d       S )Nzyt-dlp%s)templateignoredefault)r   _FILE_SUFFIXESrQ   rP   rN   rL   _get_binary_namer      s    (8:VZdhiirN   c                     d\  } }t         j                  |kD  ry t         j                  d d \  }}ddj                  t        t        |             d}t         j                  | k  rd| d| d| S d| d| d	| S )
N)   	   r      zPlease update to Python .z	 or abovezPython version z is no longer supported! zSupport for Python version z has been deprecated. )r7   version_inforF   mapstr)MIN_SUPPORTEDMIN_RECOMMENDEDmajorminor
PYTHON_MSGs        rL   _get_system_deprecationr      s    %3"M?
/)##BQ'LE5+CHHSo5N,O+PPYZJ
-' q/HUU(q7Mj\ZZrN   c                h   t        j                         }t        t        d            t	        t
        j                  j                  |       dd      5 t        fdd      D ]  }|j                  d |         	 d d d        |j                         S # 1 sw Y   |j                         S xY w)Ni   rbr   )	bufferingc                 &     j                        S N)readinto)fmvs   rL   <lambda>z_sha256_file.<locals>.<lambda>   s    ajjn rN   )hashlibsha256
memoryview	bytearrayopenr:   r;   realpathiterupdate	hexdigest)r;   hnr   r   s      @@rL   _sha256_filer      s    A	Ij)	*B	bggt$da	8 A,a0 	AHHRV	 ;;= ;;=s   *BB1c                    d| v rt         j                  | |       }n| }| d| }|r||k7  r|d| z  }|| k7  r|d|  z  }|S )Nr   @z build  from )_INVERSE_UPDATE_SOURCESry   )origintagversionchannellabels        rL   _make_labelr      sh    
f})--ff=iqE7c>77)$$&6&""LrN   c                  l    e Zd ZU dZded<   dZded<   dZded<   dZded<    e       Z	ded	<   dZ
ded
<   y)
UpdateInfoa  
    Update target information

    Can be created by `query_update()` or manually.

    Attributes:
        tag                 The release tag that will be updated to. If from query_update,
                            the value is after API resolution and update spec processing.
                            The only property that is required.
        version             The actual numeric version (if available) of the binary to be updated to,
                            after API resolution and update spec processing. (default: None)
        requested_version   Numeric version of the binary being requested (if available),
                            after API resolution only. (default: None)
        commit              Commit hash (if available) of the binary to be updated to,
                            after API resolution and update spec processing. (default: None)
                            This value will only match the RELEASE_GIT_HEAD of prerelease builds.
        binary_name         Filename of the binary to be updated to. (default: current binary name)
        checksum            Expected checksum (if available) of the binary to be
                            updated to. (default: None)
    r   r   N
str | Noner   requested_versioncommitbinary_namechecksum)__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   rP   rN   rL   r   r      sD    ( 
HGZ$(z(FJ.0K0HjrN   r   c                      e Zd ZeZeZeZdddZ	e
d        Ze
d        ZddZd ZddZd Zdd	Zdd
ZddddZefdZej.                  d        Zej.                  d        Zd Zd ZddZd ZddZy)UpdaterNc                   || _         |xs | j                  j                  d      \  | _        }| _        |s?d| j                  v s| j                  | j
                  v r| j                  | _        d | _        n/| j                  s#| j                  j                  d      d   | _        t        |      xr || j                  k7  | _        | j                  sd| _        d| _        d| j                  v r| j                  | _	        | j                  j                  d      s7| j                  | j                  k7  r| j                   j                  d| j                   j                  dd	       d
| j                   j                  | j                  | j                   j                  j                         d| j                   j                  dd              | j!                  d       nq| j
                  j#                  | j                        | _	        | j                  s;| j%                  d| j                  ddj'                  | j
                         d       t)                dt+                | _        y )Nr   r   r   latestFzyt-dlp/zYou are switching to an 
unofficialredz executable from z. Run zat your own riskz	light redzLAutomatically restarting into custom builds is disabled for security reasonszInvalid update channel z requested. Valid channels are z, T )ydl_channel
rpartitionrequested_channelrequested_tag_update_sources	partitionbool_exactrequested_repo
startswith_originreport_warning_format_errStylesEMPHASIS_block_restartry   _report_errorrF   rQ   r   _identifier)selfr   targetseps       rL   __init__zUpdater.__init__   s!   ;A;RT]]:^:^_b:c7T%7t111T5G5G4K_K_5_%)%7%7D"&*D''%)]]%<%<S%A!%DD" 6l>v'>!!!)DDK$((("&"8"8D&&11)<ATATX\XdXdAd''.txx/C/CLRW/X.Y Z HH001D1DdhhooF^F^_` a88//0BKPQST ##$rs #'"6"6":":4;Q;Q"RD&&""-d.D.D-G H**.))D4H4H*I)JLMQS -./q1B1D0EFrN   c                    t         S )zCurrent version)r   r   s    rL   current_versionzUpdater.current_version   s
     rN   c                    t         S )zCurrent commit hash)r   r   s    rL   current_commitzUpdater.current_commit  s
      rN   c                    |s| j                   }|dk(  rdnd| }d| j                   d| d| }| j                  j                  d| d|        | j                  j	                  |      j                         S )	Nr   zlatest/downloadz	download/zhttps://github.com/
/releases/r   zDownloading r   )r   r   r   write_debugurlopenread)r   namer   r;   urls        rL   _download_assetzUpdater._download_asset  s    $$C$'8O 9SE9J#D$7$7#8
4&$P|D6u=>xx$))++rN   c                8   |dk7  rd| n|}t          d| j                   d| }| j                  j                  d|        t	        j
                  | j                  j                  t        |dddd	
            j                         j                               S )Nr   ztags/r   r   zFetching release info: zapplication/vnd.github+jsonzyt-dlpz
2022-11-28)Acceptz
User-AgentzX-GitHub-Api-Version)headers)
API_BASE_URLr   r   r   jsonloadsr   r   r   decode)r   r   r   s      rL   	_call_apizUpdater._call_api  s    "hcUmCa 3 34JseD6se<=zz$((**733"$0A
 ,  DF668	 	rN   c                   t         j                  |      r|d fS | j                  |      }|dk(  r|d   }nMt        j                  dt         j
                   d|j                  dd            }|r|j                  d      nd }t        j                  t        |j                  dd            r|d   }n:t        j                  |j                  d	d            }|r|j                  d
      nd }|s|s| j                  dd       ||fS )Nr   tag_namez\s+(?P<version>z)$r   r&   r   target_commitishbodyhashzEOne of either version or commit hash must be available on the releaseTexpected)_VERSION_REra   r   r`   searchpatternry   group_HASH_PATTERN
_COMMIT_REmatchr   )r   r   api_infor   r   r   s         rL   _get_version_infozUpdater._get_version_info  s      %9>>#&(? ( 4II1D1D0ERH(,,W]_aJbcE:?I 6T<<x||4F'KL'(:;$$X\\&"%=>E6;u{{62!%5fquv "222rN   c                N   |D ]%  }	 | j                  d|      j                         c S  | j                  d| j                   d| j                   d       y # t        $ rC}t        |t              r|j
                  dk(  rY d }~| j                  d|        Y d }~ y d }~ww xY w)N_update_specr     zfetch update spec: The requested tag z does not exist for T)
r   r   r	   rD   r   status_report_network_errorr   r   r   )r   source_tagsr   errors       rL   _download_update_speczUpdater._download_update_spec1  s     	C++N+DKKMM	 	 !3!3 44HI\I\H]^`d	f & eY/ELLC4G**-@+HI	s    A	B$!BBB$c                   |j                         }t        d |D              }|D ]  }|r8|j                  d| j                   d      s%|j	                  dd      \  }}}}n(|j                  d      sO|j	                  dd      \  }}}t        j                  || j                        st        j                  |      r&| j                  s|c S | j                  ||      r
|c S ||k7  r| j                  d| dd	        y  |S )
Nc              3  >   K   | ]  }|j                  d         yw)lockV2 N)r   ).0lines     rL   	<genexpr>z/Updater._process_update_spec.<locals>.<genexpr>A  s     G$//)4Gs   r
  r   r   zlock r   zyt-dlp cannot be updated to zm since you are on an older Python version or your operating system is not compatible with the requested buildT)
splitlinesanyr   r   splitr`   r   r   r   ra   r   _version_comparer   )	r   lockfileresolved_taglinesis_version2r  r'   r   r   s	            rL   _process_update_speczUpdater._process_update_spec?  s   ##%GGG 	D1D1D0EQ'GH%)ZZQ%7"1c7w/"&**S!"43xx!1!12((-;;"
..sLA++L(""2<. AZ Z[_a -	0 rN   c                n    t         j                  | d|       rt        |      t        |      k\  S ||k(  S )zp
        Compare two version strings

        This function SHOULD NOT be called if self._exact == True
        r   )r   ra   r   )r   abs      rL   r  zUpdater._version_compare]  s:       A3as, #}Q'777AvrN   F_outputc                  | j                   s| j                  d       y	 | j                  | j                        \  }}| j                  r| j                  | j                   k7  rd}nP|r:| j                  r| j                  |k7  }n2| j                  | j                  |       }n|r|| j                  k7  }nd}| j                  d	k(  r|n| j                  }t        | j                  | j                  j                  d
      d   xs | j                  | j                        }t        | j                   ||      }| j                  d	k(  rdnd d| }	|s$|r!| j                  j                  |	 d| d       y| j!                  |rdnd      }
|
sy| j#                  |
|      }|r|| j                  k(  ry||k(  r|}nt$        j'                  |      r|}nd}d}t)               s	 | j+                  d|      }|j-                         j/                         D ]0  }|j1                  t3                     s|j5                         d   } n |s| j                  j7                  d       	 |rEt        | j                   ||      }| j                  j                  d| d|	 ||k7  rd| ndz          t?        |||||k(  r||      S d|      S # t        $ r!}| j                  d| dd       Y d}~yd}~ww xY w# t        $ r]}t9        |t:              r|j<                  dk7  r| j                  d|        Y d}~y| j                  j7                  d       Y d}~d}~ww xY w)z~Fetches info about the available update
        @returns   An `UpdateInfo` if there is an update available, else None
        z3No target repository could be determined from inputNzobtain version info (r   z; Please try again later or)delimTFr   r   r   Latest	Requestedz
 version: z
yt-dlp is up to date ()r   Nr   zSHA2-256SUMSr   zGThe hash could not be found in the checksum file, skipping verificationr  zfetch checksums: z@No hash information found for the release, skipping verificationzCurrent version: 
z
Upgradable to: r&   )r   r   r   r   r   ) r   r   r   r   r	   r  r   r   r   r  r   r   r   r   r   	to_screenr  r  r   ra   rz   r   r   r  endswithr   r  r   rD   r   r  r   )r   r  r   r   e
has_updater  current_labelrequested_labellatest_or_requestedupdate_spec
result_tagresult_versionr   hasheslnr  update_labels                     rL   query_updatezUpdater.query_updateg  sp    ""TU	262H2HI[I[2\//
 ;;4<<4+>+>>J{{!115FF
!%!6!6t7K7KM^!__
)T-@-@@JJ,0,>,>(,J(PTPbPb#DLL$--2I2I#2Nq2Q2iUYUiUikokk  A%d&9&9<IZ[-1-?-?8-KQ\ ]]ghwgxy""&9%::RS`Raab#cd00EV1A\cd..{LI
Z4+?+??<'.N"":.'N!N "w--njI !--/446 B{{#3#56#%88:a=  HH++,uv&t':':JWLHH#M?"5H4IJ9E9X&|n5^`bc "/'1\'A# 	 HL 	 " 	&&)>qc'CKh&i	X & l!%3u||s7J..1B5'/JK''(jkk	ls5   K K0 	K-K((K-0	M93M1MMc                h
   |t         u r| j                  d      }|syt               }|r| j                  |d       y| j                  j                  dt        | j                                t        | j                  |j                  |j                        }| j                  j                  d| d       t        j                  j                  | j                        }t        j                  | j                  t        j                         s| j#                  | j                        S t        j                  |t        j                         s| j#                  |      S | j                   d| j                   d}}t%               d	k(  r| j                  d
}}	 t        j                  j'                  |xs d      rt        j(                  |       	 | j-                  |j.                  |j                        }|j:                  s| j=                  d       nMt?        j@                  |      jC                         |j:                  k7  r| j9                  d|j                        S 	 tE        |d      5 }	|	jG                  |       d
d
d
       |rkt        jH                  | j                        jJ                  }
	 t        jL                  | j                  |       	 t        jL                  || j                         t%               }|jO                  d      r?tQ        jR                  tT        d| ddtV        jX                  tV        jX                         n9|r7	 t        j(                  |       	 t        jZ                  | j                  
       | j                  j                  d|        y# t*        $ r | j                  d      cY S w xY w# t0        $ r{}t3        |t4              rA|j6                  dk(  r2| j                  d| j                   d|j                   dd      cY d
}~S | j9                  d| |j                        cY d
}~S d
}~ww xY w# 1 sw Y   xY w# t*        $ r | j#                  |      cY S w xY w# t*        $ r | j                  d      cY S w xY w# t*        $ r4 | j                  d       t        jL                  || j                        cY S w xY w# t*        $ r | j                  d       Y w xY w# t*        $ r* | j                  dt]        | j                               cY S w xY w)zUpdate yt-dlp executable to the latest version
        @param update_info  `UpdateInfo | None` as returned by query_update()
        Tr  FzCurrent Build Hash: zUpdating to z ...z.newz.oldr3   Nr&   z Unable to remove the old versionr  r  r   z does not existzfetch updates: r   zPAutomatically restarting into unverified builds is disabled for security reasonszverify the new executablewbzUnable to move current versionz#Unable to overwrite current versionwinz&ping 127.0.0.1 -n 5 -w 1000 & del /F "")shellrW   rX   z0Unable to set permissions. Run: sudo chmod a+rx zUpdated yt-dlp to )/r
   r.  rz   r   r   r!  r   filenamer   r   r   r   r:   r;   r<   accessW_OK_report_permission_errorrQ   rI   removeOSErrorr   r   r	   rD   r   r  r  r   r   r   r   r   r   writestatst_moderenamer   atexitregisterr   r^   DEVNULLchmodr   )r   update_infoerrr-  	directorynew_filenameold_filename
newcontentr#  outfmaskvariants               rL   r   zUpdater.update  sd    *$++D+9K!sD)1,t}}2M1NOP"4#6#6I\I\]\,t<=GGOODMM2	yy000??9bgg.00;;(,d%;d=Slu$)-,L	Jww~~l0b1		,'	Z--k.E.E{WJ ## rs^^J'113{7K7KK--.I{-__	?lD) 'T

:&'
 774==)11DL		$--6>		,6
 !"e$OOE%KL>YZ#["&z/A/A*J\J\^G		,'e-
 	/~>?i  	J%%&HII	J
 " 	Z!Y'AHHO))()<)<(=Q{>O_aeg g--s.C-YY		Z' ' 	?00>>	?  L))*JKKL
  >""#HIyyt}}==>  G""#EFG
  e))F{SWS`S`GaFbce ees   8N) &O	 $Q 0QQ 6 Q=  R S * S> )OO		QAQQ#QQQQQ Q:9Q:=RR:SSS;:S;>0T10T1c                V    t         j                  j                  t               d         S )zFilename of the executabler   )r:   r;   r   rM   r   s    rL   r4  zUpdater.filename  s"     ww @ B1 EFFrN   c                    d}t        t        dd      rt        j                  }n!t        t        dd      rt        j                  }|r't	        j
                  d      r| j                  g|dd }|S )z0The command-line to run the executable, if knownN	orig_argvr   Fr0   r   )r6   r7   rM  rH   r:   rB   r4  )r   rH   s     rL   cmdzUpdater.cmd  s^     3T*==DS(E*88DBII12MM-DH-DrN   c                    | j                   sJ d       | j                  j                  dt        | j                                 t	        j
                  | j                         \  }}}|S )zRestart the executablezMust be frozen or Py >= 3.10zRestarting: )rN  r   r   r   r   r\   )r   r'   
returncodes      rL   restartzUpdater.restart   sV    xx777x|K,A+BCD 99TXX.1jrN   c                "      fd}| _         y )Nc                 \    j                    dd       j                  j                  S )Nz+. Restart yt-dlp to use the updated versionTr   )r   r   _download_retcode)msgr   s   rL   wrapperz'Updater._block_restart.<locals>.wrapper(  s/    #&QR]ab88---rN   )rQ  )r   rU  rV  s   `` rL   r   zUpdater._block_restart'  s    	. rN   c                h    | j                   j                  ||rdnd        d| j                   _        y )NF)tbd   )r   report_errorrT  )r   rU  r   s      rL   r   zUpdater._report_error-  s)    cxeTB%("rN   c                0    | j                  d| dd       y )NzUnable to write to z; try running as administratorT)r   )r   files     rL   r7  z Updater._report_permission_error1  s    06TUW[\rN   c           	         |s| j                   }|dk(  r|nd| }| j                  d| | d| j                   d| d       y )Nr   ztag/z
Unable to z visit  https://github.com/r   T)r   r   r   )r   actionr  r   r;   s        rL   r  zUpdater._report_network_error4  s]    $$CXosT#< (""&"5"5!6jHIM	OrN   r   )r   r   )r   r   returnztuple[str | None, str | None])r  r   r  r   )r  r   r  r   )r_  zUpdateInfo | None)F);N)r   r   r   r   r   r   r   UPDATE_SOURCESr   r   propertyr   r   r   r   r   r  r  r  r.  r
   r   	functoolscached_propertyr4  rN  rQ  r   r   r7  r  rP   rN   rL   r   r      s    HG$O$GL      ,3.< ', N` ", Tl G G  )]OrN   r   c                J    t        d       t        |       j                         S )zUpdate the program file with the latest version from the repository
    @returns    Whether there was a successful update (No update = False)
    z"yt_dlp.update.run_update(ydl)" is deprecated and may be removed in a future version. Use "yt_dlp.update.Updater(ydl).update()" instead)r   r   r   )r   s    rL   
run_updaterf  =  s&     	<= 3<  rN   r   )@
__future__r   r>  rY   rc  r   r   r:   r=   r`   r^   r7   dataclassesr   	zipimportr   
networkingr   networking.exceptionsr   r	   utilsr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ra  
REPOSITORYitemsr   compiler   r   r   r   API_URLcacherM   rQ   rc   r   dictfromkeysrx   rz   r   r   r   r   r   r   rf  __all__)keyvaluerJ  r   s   0000rL   <module>rw     s   "      	  	  
 ! !  @	 	 	  -+
 H%
8F8L8L8NO*#u5#:O bjj(RZZTUbTccdef
- N!J<y
1    F< 	" 	" ()'	
mmN# +47Y`aggik7D >tfDopp k [cgV Vj[
      <iO iOX! +y P\ks   E8+E>