
    V|h                          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SKJ	r	J
r
JrJr  SSKJr   " S S\5      r " S	 S
\S9r " S S\	5      rg)    N   )Request)	HTTPErrornetwork_exceptions)PostProcessingErrorRetryManager_configuration_argsdeprecation_warning)_ProgressStatec                   *    \ rS rSr\S 5       rS rSrg)PostProcessorMetaClass   c                 F   ^  [         R                  " T 5      U 4S j5       nU$ )Nc                    > U R                  U5      nU R                  SS0U5        T" X/UQ70 UD6nUb  Uu  paU R                  SS0U5        U$ )Nstatusstartedfinished)_copy_infodict_hook_progress)selfinfoargskwargs	info_copyret_funcs          U/home/james-whalen/.local/lib/python3.13/site-packages/yt_dlp/postprocessor/common.pyrun/PostProcessorMetaClass.run_wrapper.<locals>.run   sb    ++D1I9 5yAt3D3F3C: 6	BJ    	functoolswraps)r   r   s   ` r   run_wrapper"PostProcessorMetaClass.run_wrapper   s%    			 
	 
r!   c                 h    SU;   a  U R                  US   5      US'   [        R                  XX#5      $ )Nr   )r%   type__new__)clsnamebasesattrss       r   r)   PostProcessorMetaClass.__new__   s0    E>??5<8E%L||Cu44r!    N)__name__
__module____qualname____firstlineno__staticmethodr%   r)   __static_attributes__r/   r!   r   r   r      s    
 
5r!   r   c                       \ rS rSrSrSrSS jr\S 5       rSS jr	S r
S	 rS
 rS rS rS rSS jrS rS r\SSSSS.S j5       rS rS S jrS rS rS rS rS rSS.S jrSrg)!PostProcessor$   a?  Post Processor class.

PostProcessor objects can be added to downloaders with their
add_post_processor() method. When the downloader has finished a
successful download, it will take its internal chain of PostProcessors
and start calling the run() method on each one of them, first with
an initial argument and then with the returned value of the previous
PostProcessor.

PostProcessor objects follow a "mutual registration" process similar
to InfoExtractor objects.

Optionally PostProcessor can use a list of additional command-line arguments
with self._configuration_args.
Nc                     / U l         U R                  U R                  5        U R                  U5        U R	                  5       U l        g N)_progress_hooksadd_progress_hookreport_progressset_downloaderpp_keyPP_NAME)r   
downloaders     r   __init__PostProcessor.__init__7   s9    !t334J'{{}r!   c                 \    U R                   S S nUS S R                  5       S:X  a  USS  $ U$ )N   ffmpeg)r0   lower)r*   r+   s     r   r?   PostProcessor.pp_key=   s7    ||CR 8>>+x7tABxATAr!   Tc                     U R                   (       a=  U(       a  SU R                   S3OSnU R                   R                  " U U 3/UQ70 UD6$ g )N[z]  )_downloaderr@   	to_screen)r   textprefixr   r   tags         r   rN   PostProcessor.to_screenB   sO    *0Adll^2&bC##--dVnNtNvNN r!   c                 f    U R                   (       a   U R                   R                  " U/UQ70 UD6$ g r:   )rM   report_warningr   rO   r   r   s       r   rT   PostProcessor.report_warningG   s1    ##224I$I&II r!   c                 F    [        U R                  S[        5      nU" USS9$ )Nr
      
stacklevel)getattrrM   r
   )r   msgwarns      r   r
   !PostProcessor.deprecation_warningK   s%    t'')>@STCA&&r!   c                 n    U R                   (       a  U R                   R                  U5      $ [        USS9$ )NrX   rY   )rM   deprecated_featurer
   )r   r\   s     r   r`    PostProcessor.deprecated_featureO   s/    ##66s;;"3155r!   c                     U R                  S5        U R                  (       a   U R                  R                  " U/UQ70 UD6$ g )Nzq"yt_dlp.postprocessor.PostProcessor.report_error" is deprecated. raise "yt_dlp.utils.PostProcessingError" instead)r
   rM   report_errorrU   s       r   rc   PostProcessor.report_errorT   sF       "T 	U##00GGGG r!   c                 f    U R                   (       a   U R                   R                  " U/UQ70 UD6$ g r:   )rM   write_debugrU   s       r   rf   PostProcessor.write_debugZ   s1    ##//FtFvFF r!   c                     U R                   (       a  U R                   R                  " U0 UD6$ [        [        S U5      5       H  n[        R
                  " U5        M     g r:   )rM   _delete_downloaded_filessetfilterosremove)r   files_to_deleter   filenames       r   ri   &PostProcessor._delete_downloaded_files^   sJ    ##<<oXQWXXF49:HIIh ;r!   c                 |    U R                   (       a*  U R                   R                  R                  " X/UQ70 UD6$ U$ r:   )rM   paramsget)r   r+   defaultr   r   s        r   	get_paramPostProcessor.get_paramd   s7    ##**..tNtNvNNr!   c                 Z    Xl         [        US/ 5       H  nU R                  U5        M     g)z Sets the downloader for this PP._postprocessor_hooksN)rM   r[   r<   )r   rA   phs      r   r>   PostProcessor.set_downloaderi   s+    %*&<bAB""2& Br!   c                 D    [        U R                  S[        5      " U5      $ )Nr   )r[   rM   dict)r   	info_dicts     r   r   PostProcessor._copy_infodicto   s    t'')94@KKr!   )videoaudioimages	simulatedc                 "   ^^ XUS.mUU4S jnU$ )N)r   r   r   c                 L   >^  [         R                  " T 5      UU U4S j5       nU$ )Nc                 &  > T(       d0  U R                  S5      (       d  U R                  S5      (       a  / U4$ UR                  S5      S:w  a  SOUR                  S5      S:w  a  SOSnTU   (       a  T" X5      $ U R                  S	U 35        / U4$ )
Nsimulateskip_downloadvcodecnoner   acodecr   r   z	Skipping )ru   rs   rN   )r   r   format_typeallowedr   r   s      r   wrapper>PostProcessor._restrict_to.<locals>.decorator.<locals>.wrapperw   s     dnnZ&@&@DNNSbDcDct8O#xx1V;G$(HHX$6&$@!  ;'++NNY{m#<=t8Or!   r"   )r   r   r   r   s   ` r   	decorator-PostProcessor._restrict_to.<locals>.decoratorv   s%    __T"$ #$ Nr!   r/   )r   r   r   r   r   r   s      ` @r   _restrict_toPostProcessor._restrict_tor   s    !VD	 r!   c                 
    / U4$ )a  Run the PostProcessor.

The "information" argument is a dictionary like the ones
composed by InfoExtractors. The only difference is that this
one has an extra field called "filepath" that points to the
downloaded file.

This method returns a tuple, the first element is a list of the files
that can be deleted, and the second of which is the updated
information.

In addition, this method may raise a PostProcessingError
exception if post processing fails.
r/   )r   informations     r   r   PostProcessor.run   s     ;r!   c                 x     [         R                  " XU45        g ! [         a    U R                  U5         g f = fr:   )rl   utime	ExceptionrT   )r   pathatimemtimeerrnotes        r   	try_utimePostProcessor.try_utime   s4    	)HHT5>* 	)(	)s    99c                 ^    [        U R                  5       U R                  S5      U/UQ70 UD6$ )Npostprocessor_args)r	   r?   ru   )r   exer   r   s       r   r	   !PostProcessor._configuration_args   s:    "KKM4>>*>?WGKWOUW 	Wr!   c                     U R                   (       d  g UR                  UU R                  5       S.5        U R                    H  nU" U5        M     g )N)r}   postprocessor)r;   updater?   )r   r   r}   ry   s       r   r   PostProcessor._hook_progress   sD    ##"![[]
 	 &&BvJ 'r!   c                 :    U R                   R                  U5        g r:   )r;   append)r   ry   s     r   r<   PostProcessor.add_progress_hook   s    ##B'r!   c                 (   SU-  US'   U R                   (       d  g UR                  5       nUR                  S5        US   US.nU R                  S0 5      nUR	                  S5      nU(       a3  U R                   R                  U R                   R                  XB5      SS9  U R                   R                  U R                   R                  UR	                  S	5      =(       d    S
U5      [        R                  " U5      UR	                  S5      5        g )Nz%(postprocessor)s %(status)s_default_templater}   )r   progressprogress_templatepostprocessF)quietzpostprocess-titlez%yt-dlp %(progress._default_template)s_percent)
rM   copypopru   rs   rN   evaluate_outtmplto_console_titler   	from_dict)r   sprogress_dictr   tmpls        r   r=   PostProcessor.report_progress   s    !?!!C
+&!";]K NN+>C $$]3&&  11$Fe ' U 	))$*:*:*K*K!!"56a:a+*44Q7z9J	Lr!   c                     [         R                  " XX0R                  U R                  U R	                  S0 5      R                  S5      S9  g )Nretry_sleep_functions	extractor)r   r]   
sleep_func)r   report_retryrN   rT   ru   rs   )r   errcountretriess       r   _retry_downloadPostProcessor._retry_download   s@     	!!#gNNQUQdQd-1^^<SUW-X-\-\]h-i	kr!   )i  )expected_http_errorsc                V   U R                  U R                   SU 35        [        U R                  SS5      U R                  5       H(  n U R
                  R                  [        U5      5      nM*     [        R                  " WR!                  5       R#                  UR$                  R                  S5      =(       d    S5      5      $ ! [         aV  n[        U[        5      (       a  UR                  U;   a   S nA  g [        SU R                   SU 35      Ul         S nAM  S nAff = f)Nz query: extractor_retries   zUnable to communicate with z API: charsetzutf-8)rf   r@   r   ru   r   rM   urlopenr   r   
isinstancer   r   r   errorjsonloadsreaddecodeheaders)r   urlr   retryrspes         r   _download_jsonPostProcessor._download_json   s    DLL>#78!$..1Da"H$J^J^_E&&..ws|< ` zz#((*++CKK,A,A),L,WPWXYY & a++<P0P14OPTP\P\~]cdecf2gh	s   $C
D(%D#= D##D()r@   rM   r;   r:   )T)zCannot update utime of file)r0   r1   r2   r3   __doc__rM   rB   classmethodr?   rN   rT   r
   r`   rc   rf   ri   ru   r>   r   r4   r   r   r   r	   r   r<   r=   r   r   r5   r/   r!   r   r7   r7   $   s      K% B BO
J'6
HG 
'L "$tt  (")W(L&k ;A 
Z 
Zr!   r7   )	metaclassc                       \ rS rSrSrg)AudioConversionError   r/   N)r0   r1   r2   r3   r5   r/   r!   r   r   r      s    r!   r   )r#   r   rl   
networkingr   networking.exceptionsr   r   utilsr   r   r	   r
   utils._utilsr   r(   r   r7   r   r/   r!   r   <module>r      sN      	   A  *5T 5(oZ4 oZd	. 	r!   